Skip to content

An OpenMW mod that lets you play the whole Elder Scrolls III: Morrowind as a top-down isometric game — with full online co-op or MMO modes.

C++

Isowind df6a5ee: README: MMO respawns with players there; kill quests count your own kills

Isowinde7d79d02546b
diff --git a/apps/openmw/mwmp/MechanicsHelper.cpp b/apps/openmw/mwmp/MechanicsHelper.cpp
index ff12a37..7e590d5 100644
--- a/apps/openmw/mwmp/MechanicsHelper.cpp
+++ b/apps/openmw/mwmp/MechanicsHelper.cpp
@@ -14,6 +14,8 @@
#include "../mwbase/luamanager.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/windowmanager.hpp"
+#include "../mwgui/mode.hpp"
+#include "Hooks.hpp"
#include "../mwbase/world.hpp"
#include "../mwworld/scene.hpp"
@@ -109,21 +111,44 @@ void MechanicsHelper::spawnLeveledCreatures(MWWorld::CellStore* cellStore)
bool MechanicsHelper::respawnActor(const MWWorld::Ptr& ptr)
{
- if (ptr.isEmpty() || !ptr.getClass().isActor() || ptr.getCell()->getState() != MWWorld::CellStore::State_Loaded
- || MWBase::Environment::get().getWorldScene()->isCellActive(*ptr.getCell()))
+ if (ptr.isEmpty() || !ptr.getClass().isActor() || ptr.getCell()->getState() != MWWorld::CellStore::State_Loaded)
return false;
+ MWBase::World* world = MWBase::Environment::get().getWorld();
+ MWBase::WindowManager* windowManager = MWBase::Environment::get().getWindowManager();
+
+ // Someone looting its body stops: the body is gone
+ if (mwmp::hooks::isCurrentContainer(ptr) && windowManager->containsMode(MWGui::GM_Container))
+ windowManager->removeGuiMode(MWGui::GM_Container);
+
+ // In a cell in use it leaves the scene while it's reset and comes back into it fresh (as for Disable/Enable: its
+ // animation, physics and AI start over); a disabled one (a quest's) stays disabled
+ const bool inScene = MWBase::Environment::get().getWorldScene()->isCellActive(*ptr.getCell())
+ && ptr.getRefData().isEnabled();
+ if (inScene)
+ {
+ if (ptr.getCellRef().getCount() > 0)
+ {
+ world->removeContainerScripts(ptr);
+ world->disable(ptr);
+ }
+ else
+ ptr.getRefData().disable(); // a body cleared away: enabling below puts it back
+ }
+
// What Npc::respawn and Creature::respawn do, whatever the Respawn flag and time since death (its local
// script comes back when the cell becomes active)
- MWBase::World* world = MWBase::Environment::get().getWorld();
if (ptr.getCellRef().getCount() == 0)
ptr.getCellRef().setCount(1);
- MWBase::Environment::get().getWindowManager()->onDeleteCustomData(ptr);
+ windowManager->onDeleteCustomData(ptr);
ptr.getRefData().setCustomData(nullptr);
const ESM::Position& start = ptr.getCellRef().getPosition();
MWWorld::Ptr moved = world->moveObject(ptr, ptr.getCell()->getOriginCell(ptr), start.asVec3());
world->rotateObject(moved, start.asRotationVec3(), MWBase::RotationFlag_none);
+
+ if (inScene)
+ world->enable(moved);
return true;
}
diff --git a/apps/openmw/mwmp/MechanicsHelper.hpp b/apps/openmw/mwmp/MechanicsHelper.hpp
index 9d4a6fe..2267828 100644
--- a/apps/openmw/mwmp/MechanicsHelper.hpp
+++ b/apps/openmw/mwmp/MechanicsHelper.hpp
@@ -16,7 +16,8 @@ namespace MechanicsHelper
void spawnLeveledCreatures(MWWorld::CellStore* cellStore);
/// Isowind MMO: an actor the server brings back (respawns), alive and fresh at its starting place, as when
- /// Morrowind respawns one. Only for cells nobody here is in; returns whether it was done.
+ /// Morrowind respawns one, in front of the players there too. Returns whether it was done (not for cells this
+ /// game hasn't loaded, where it's as it starts anyway).
bool respawnActor(const MWWorld::Ptr& ptr);
bool isUsingRangedWeapon(const MWWorld::Ptr& ptr);
diff --git a/apps/openmw/mwmp/ObjectList.cpp b/apps/openmw/mwmp/ObjectList.cpp
index 8f1767e..e06046a 100644
--- a/apps/openmw/mwmp/ObjectList.cpp
+++ b/apps/openmw/mwmp/ObjectList.cpp
@@ -1005,7 +1005,7 @@ void ObjectList::runConsoleCommands(MWWorld::CellStore* cellStore)
if (consoleCommand == "isowind respawn")
{
if (!MechanicsHelper::respawnActor(ptrFound))
- LOG_APPEND(TimedLog::LOG_INFO, "-- Not respawned here (its cell is in use)");
+ LOG_APPEND(TimedLog::LOG_INFO, "-- Not respawned here (not an actor)");
continue;
}
diff --git a/isowind/README.txt b/isowind/README.txt
index 99e16af..0e3c7c9 100644
--- a/isowind/README.txt
+++ b/isowind/README.txt
@@ -50,9 +50,11 @@ Hosting a server
- Name, port (25565 unless you change it), most players, and a password (empty: anyone can join).
- Game: Co-op is one shared world, as in single player. MMO gives everyone their own loot
(containers, corpses, plants, items lying around) and their own quests, and enemies and NPCs
- come back after they die once no one is nearby: weak ones after 1.5 minutes, normal ones 5,
+ come back after they die, players there or not: weak ones after 1.5 minutes, normal ones 5,
tough ones 15, bosses 20 ("Enemy respawns" speeds that up or slows it down). Plants and ore
you harvested grow back for you after 10 minutes; chests don't refill.
+ Quests that count kills (like the Fighters Guild's rats) count the kills you made yourself,
+ or your party made; someone else killing them first doesn't take them from you, they come back.
- PvP (whether players can hurt each other), difficulty and how fast the time of day goes.
Then a server window opens; close it to stop the server.
2. Press Join (the address is set to this computer) to play on it yourself.
diff --git a/isowind/server/CoreScripts/scripts/custom/isowindMmo.lua b/isowind/server/CoreScripts/scripts/custom/isowindMmo.lua
index 6d1a979..c7e5d73 100644
--- a/isowind/server/CoreScripts/scripts/custom/isowindMmo.lua
+++ b/isowind/server/CoreScripts/scripts/custom/isowindMmo.lua
@@ -7,7 +7,7 @@
-- * Quests, topics, factions, bounties, reputation and kill counts are each player's own, and so is what quest scripts
-- do to the world's own people and things: enabling or disabling them (isowindStates) or deleting them (isowindTaken),
-- so a quest that removes someone for one player leaves them there for the others.
--- * Enemies and NPCs come back after they die, once no player is in or next to their cell, after a time from how
+-- * Enemies and NPCs come back after they die, players there or not, after a time from how
-- tough they were (WoW-like tiers, from their health): trash 1.5 minutes, normal 5, elite 15, bosses 20, divided by
-- the host's respawn speed. Ones from the game's files are reset on each client ("isowind respawn", a console
-- command packet the game handles itself); leveled-list ones are spawned again where they first appeared.
@@ -53,7 +53,6 @@ local regrowPatterns = { "^flora_", "^rock_", "^egg_kwama" }
local seenCells = {}
local regrown = {}
-local isAreaEmpty
local function playerKey(pid)
return string.lower(Players[pid].accountName)
@@ -348,6 +347,30 @@ local function onObjectState(eventStatus, pid, cellDescription, objects)
return customEventHooks.makeEventStatus(false, true)
end
+-- Plants and ore that grew back, to a player's game that still has them harvested: { uniqueIndex = { refId, items } }
+local function sendRegrown(pid, cellDescription, grown)
+ tes3mp.ClearObjectList()
+ tes3mp.SetObjectListPid(pid)
+ tes3mp.SetObjectListCell(cellDescription)
+ for uniqueIndex, entry in pairs(grown) do
+ local refNum, mpNum = splitIndex(uniqueIndex)
+ tes3mp.SetObjectRefNum(refNum)
+ tes3mp.SetObjectMpNum(mpNum)
+ tes3mp.SetObjectRefId(entry.refId)
+ for _, item in pairs(entry.items) do
+ tes3mp.SetContainerItemRefId(item.refId)
+ tes3mp.SetContainerItemCount(-item.count)
+ tes3mp.SetContainerItemCharge(item.charge)
+ tes3mp.SetContainerItemEnchantmentCharge(item.enchantmentCharge)
+ tes3mp.SetContainerItemSoul(item.soul)
+ tes3mp.AddContainerItem()
+ end
+ tes3mp.AddObject()
+ end
+ tes3mp.SetObjectListAction(enumerations.container.ADD)
+ tes3mp.SendContainer(false, false)
+end
+
-- A player loading a cell gets their own loot and pickups there on top of the shared state just sent
local function onCellLoad(eventStatus, pid, cellDescription)
local cell = LoadedCells[cellDescription]
@@ -431,26 +454,7 @@ local function onCellLoad(eventStatus, pid, cellDescription)
-- What grew back since their game last had this cell loaded (their game still has it harvested)
local grown = regrown[name] ~= nil and regrown[name][cellDescription] or nil
if grown ~= nil then
- tes3mp.ClearObjectList()
- tes3mp.SetObjectListPid(pid)
- tes3mp.SetObjectListCell(cellDescription)
- for uniqueIndex, entry in pairs(grown) do
- local refNum, mpNum = splitIndex(uniqueIndex)
- tes3mp.SetObjectRefNum(refNum)
- tes3mp.SetObjectMpNum(mpNum)
- tes3mp.SetObjectRefId(entry.refId)
- for _, item in pairs(entry.items) do
- tes3mp.SetContainerItemRefId(item.refId)
- tes3mp.SetContainerItemCount(-item.count)
- tes3mp.SetContainerItemCharge(item.charge)
- tes3mp.SetContainerItemEnchantmentCharge(item.enchantmentCharge)
- tes3mp.SetContainerItemSoul(item.soul)
- tes3mp.AddContainerItem()
- end
- tes3mp.AddObject()
- end
- tes3mp.SetObjectListAction(enumerations.container.ADD)
- tes3mp.SendContainer(false, false)
+ sendRegrown(pid, cellDescription, grown)
regrown[name][cellDescription] = nil
end
@@ -458,7 +462,8 @@ local function onCellLoad(eventStatus, pid, cellDescription)
seenCells[name][cellDescription] = true
end
--- Plants and ore due to grow back, for players not near them: their harvest is forgotten, and a player whose game has
+-- Plants and ore due to grow back: the player's harvest is forgotten, and their game gets the plant back now if they're
+-- there, else the next time it loads the cell (if it has it loaded this session); the first line goes on as before:
-- the cell loaded this session gets the plant back the next time they load it
local function checkRegrowth()
local regrowths = getRegrowths()
@@ -473,15 +478,24 @@ local function checkRegrowth()
end
end
end
- if #ready > 0 and isAreaEmpty(cellDescription) then
+ if #ready > 0 then
withCell(cellDescription, function(cell)
local loot = cell.data.isowindLoot or {}
for _, entry in ipairs(ready) do
local record = loot[entry.uniqueIndex]
local mine = record ~= nil and record.players[entry.name] or nil
+ local here = nil
+ for _, visitor in pairs(cell.visitors) do
+ if Players[visitor] ~= nil and playerKey(visitor) == entry.name then
+ here = visitor
+ end
+ end
if mine ~= nil then
record.players[entry.name] = nil
- if seenCells[entry.name] ~= nil and seenCells[entry.name][cellDescription] then
+ if here ~= nil then
+ sendRegrown(here, cellDescription, { [entry.uniqueIndex] = { refId = record.refId,
+ items = mine } })
+ elseif seenCells[entry.name] ~= nil and seenCells[entry.name][cellDescription] then
regrown[entry.name] = regrown[entry.name] or {}
regrown[entry.name][cellDescription] = regrown[entry.name][cellDescription] or {}
regrown[entry.name][cellDescription][entry.uniqueIndex] =
@@ -571,31 +585,6 @@ local function onActorDeath(eventStatus, pid, cellDescription, actors)
WorldInstance:QuicksaveToDrive()
end
--- No player in the cell, or (outdoors) in the cells around it that their game has loaded
-function isAreaEmpty(cellDescription)
- local loaded = LoadedCells[cellDescription]
- if loaded ~= nil and tableHelper.getCount(loaded.visitors) > 0 then
- return false
- end
- local x, y = cellDescription:match("^(%-?%d+), (%-?%d+)$")
- for _, player in pairs(Players) do
- if player:IsLoggedIn() and player.data.location ~= nil then
- local playerCell = player.data.location.cell
- if playerCell == cellDescription then
- return false
- end
- if x ~= nil then
- local px, py = playerCell:match("^(%-?%d+), (%-?%d+)$")
- if px ~= nil and math.abs(tonumber(px) - tonumber(x)) <= 1 and
- math.abs(tonumber(py) - tonumber(y)) <= 1 then
- return false
- end
- end
- end
- end
- return true
-end
-
local function respawnInCell(cellDescription, uniqueIndexes)
local fromGameFiles = {}
local leveled = {}
@@ -670,7 +659,7 @@ local function checkRespawns()
table.insert(ready, uniqueIndex)
end
end
- if #ready > 0 and isAreaEmpty(cellDescription) then
+ if #ready > 0 then
respawnInCell(cellDescription, ready)
for _, uniqueIndex in ipairs(ready) do
due[uniqueIndex] = nil
diff --git a/isowind/server/CoreScripts/scripts/eventHandler.lua b/isowind/server/CoreScripts/scripts/eventHandler.lua
index 82d7d9f..164bceb 100644
--- a/isowind/server/CoreScripts/scripts/eventHandler.lua
+++ b/isowind/server/CoreScripts/scripts/eventHandler.lua
@@ -206,15 +206,21 @@ eventHandler.InitializeDefaultHandlers = function()
else
- -- Isowind: each player's own kill counts - the killer's, their allies' and those of the players who hit
- -- it in the last 10 minutes - each sent only to them
+ -- Isowind: each player's own kill counts - the killer's, their allies' (party's) and those of the players
+ -- who hit it in the last 10 minutes - each sent only to them. The killer, not the player whose game
+ -- reported the death (whoever's game runs that cell): someone standing by gets no credit.
for uniqueIndex, actor in pairs(actors) do
- local recipients = { pid }
+ local recipients = {}
local names = {}
+ local killerPid = actor.killer ~= nil and actor.killer.pid or nil
- for _, alliedName in ipairs(Players[pid].data.alliedPlayers or {}) do
- table.insert(names, alliedName)
+ if killerPid ~= nil and Players[killerPid] ~= nil and Players[killerPid]:IsLoggedIn() then
+ table.insert(recipients, killerPid)
+
+ for _, alliedName in ipairs(Players[killerPid].data.alliedPlayers or {}) do
+ table.insert(names, alliedName)
+ end
end
if sendKills[uniqueIndex] ~= nil and os.time() - sendKills[uniqueIndex].timestamp < 600 then
diff --git a/isowind/server/tests/mmotest.lua b/isowind/server/tests/mmotest.lua
index b962f68..02dd3a3 100644
--- a/isowind/server/tests/mmotest.lua
+++ b/isowind/server/tests/mmotest.lua
@@ -162,7 +162,7 @@ local function runTests()
-- A dead mudcrab comes back after 1.5 minutes, once no one is near
cell.data.objectData["999-0"] = { refId = "mudcrab", stats = { healthBase = 35 } }
customEventHooks.triggerHandlers("OnActorDeath", customEventHooks.makeEventStatus(true, true),
- { pid, CELL, { ["999-0"] = { refId = "mudcrab", killer = {} } } })
+ { pid, CELL, { ["999-0"] = { refId = "mudcrab", killer = { pid = pid } } } })
local due = WorldInstance.data.isowindRespawns[CELL]["999-0"]
check("mudcrab due in about 90 seconds", due ~= nil and math.abs(due - os.time() - 90) <= 2)
@@ -217,21 +217,13 @@ local function runTests()
{ pid, CELL, { ["996-0"] = { refId = "quest_npc", killer = {} } } })
WorldInstance.data.isowindRespawns[CELL]["996-0"] = os.time() - 1
- -- Not while the player is there
- WorldInstance.data.isowindRespawns[CELL]["999-0"] = os.time() - 1
+ -- Not before its time
sent = {}
IsowindMmoRespawnTimer()
- check("no respawn with the player in the cell", lastSent("SendConsoleCommand") == nil)
-
- -- The player walks off, next to the cell: still not
- Players[pid].data.location.cell = "-2, 6"
- cell.visitors = {}
- IsowindMmoRespawnTimer()
- check("no respawn with the player next door", lastSent("SendConsoleCommand") == nil)
+ check("no respawn before its time", lastSent("SendConsoleCommand") == nil)
- -- Far away: it respawns
- Players[pid].data.location.cell = "10, 10"
- logicHandler.UnloadCell(CELL)
+ -- On time, with the player standing in the cell
+ WorldInstance.data.isowindRespawns[CELL]["999-0"] = os.time() - 1
IsowindMmoRespawnTimer()
local respawn = lastSent("SendConsoleCommand")
check("respawn sent to everyone", respawn ~= nil and respawn.command == "isowind respawn" and
@@ -239,13 +231,27 @@ local function runTests()
check("respawn names the mudcrab", respawn ~= nil and respawn.objects[1] ~= nil and
respawn.objects[1].refNum == "999" or (respawn ~= nil and respawn.objects[1] ~= nil and
tostring(respawn.objects[1].refNum) == "999"))
- logicHandler.LoadCell(CELL)
cell = LoadedCells[CELL]
check("mudcrab's death forgotten", cell.data.objectData["999-0"] == nil)
check("disabled one not brought back", cell.data.objectData["996-0"] ~= nil and
cell.data.objectData["996-0"].state == false)
check("boss still waiting", WorldInstance.data.isowindRespawns[CELL]["998-0"] ~= nil)
+ -- A plant grows back in front of its harvester: their game gets it at once
+ receive({ action = REMOVE, objects = { { refNum = 4322, mpNum = 0, refId = "flora_marshmerrow_01",
+ items = { { refId = "ingred_marshmerrow_01", count = 2, actionCount = 2 } } } } })
+ validate("OnContainer", { pid, CELL, {} })
+ WorldInstance.data.isowindRegrow[CELL]["4322-0"].alpha = os.time() - 1
+ cell.visitors = { pid }
+ sent = {}
+ IsowindMmoRespawnTimer()
+ local grownHere = nil
+ for _, packet in ipairs(sent) do
+ if packet.name == "SendContainer" and packet.action == ADD then grownHere = packet end
+ end
+ check("plant given back at once to the harvester standing there", grownHere ~= nil and
+ grownHere.objects[1].items[1].count == 2)
+
-- Plants grow back for the harvester
Players[pid].data.location.cell = CELL
receive({ action = REMOVE, objects = { { refNum = 4321, mpNum = 0, refId = "flora_kreshweed_01",
diff --git a/isowind/server/tests/partytest.lua b/isowind/server/tests/partytest.lua
index 2e5ed36..51ddd0b 100644
--- a/isowind/server/tests/partytest.lua
+++ b/isowind/server/tests/partytest.lua
@@ -138,7 +138,7 @@ local function runTests()
beta.data.kills = nil
cell.data.objectData["555-0"] = { refId = "mudcrab", stats = { healthBase = 35 } }
customEventHooks.triggerHandlers("OnActorDeath", customEventHooks.makeEventStatus(true, true),
- { 0, "-3, 6", { ["555-0"] = { refId = "mudcrab", killer = {} } } })
+ { 0, "-3, 6", { ["555-0"] = { refId = "mudcrab", killer = { pid = 0 } } } })
check("party member gets the kill", beta.data.kills ~= nil and beta.data.kills.mudcrab == 1)
-- Catching up at login
@@ -154,6 +154,22 @@ local function runTests()
check("no longer allies", #alpha.data.alliedPlayers == 0 and #beta.data.alliedPlayers == 0)
check("Beta keeps the quests", hasJournal(beta, "a1_1_findspymaster", 1))
+ -- Not in a party: Beta's game (running the cell) reports a rat Alpha killed; Alpha gets it, not Beta
+ alpha.data.kills = {}
+ beta.data.kills = {}
+ cell.data.objectData["556-0"] = { refId = "rat_cave_fgrh", stats = { healthBase = 8 } }
+ customEventHooks.triggerHandlers("OnActorDeath", customEventHooks.makeEventStatus(true, true),
+ { 1, "-3, 6", { ["556-0"] = { refId = "rat_cave_fgrh", killer = { pid = 0 } } } })
+ check("the killer gets the kill", alpha.data.kills.rat_cave_fgrh == 1)
+ check("whoever's game reported it doesn't", beta.data.kills.rat_cave_fgrh == nil)
+
+ -- A rat killed by a guard: no one's
+ cell.data.objectData["557-0"] = { refId = "rat_cave_fgrh", stats = { healthBase = 8 } }
+ customEventHooks.triggerHandlers("OnActorDeath", customEventHooks.makeEventStatus(true, true),
+ { 1, "-3, 6", { ["557-0"] = { refId = "rat_cave_fgrh", killer = { refId = "imperial guard", name = "Guard" } } } })
+ check("a kill by someone else counts for no player", alpha.data.kills.rat_cave_fgrh == 1 and
+ beta.data.kills.rat_cave_fgrh == nil)
+
-- Alone again: a quest script is just theirs
customEventHooks.triggerValidators("OnObjectState", { 0, "-3, 6", { ["7778-0"] = { refId = "quest_npc2",
uniqueIndex = "7778-0", state = false } }, {} })