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 1f4acef: Multiplayer chat closes after sending; Escape closes it; MMO guesses weak creatures

Isowind8e0f6d0d6d2d
diff --git a/apps/openmw/mwmp/GUI/GUIChat.cpp b/apps/openmw/mwmp/GUI/GUIChat.cpp
index 2019dde..33cd56f 100644
--- a/apps/openmw/mwmp/GUI/GUIChat.cpp
+++ b/apps/openmw/mwmp/GUI/GUIChat.cpp
@@ -80,6 +80,7 @@ namespace mwmp
{
mCommandLine->setCaption("");
setEditState(false);
+ closedByEnter = true;
return;
}
@@ -97,6 +98,7 @@ namespace mwmp
// during the actual command execution
mCommandLine->setCaption("");
setEditState(false);
+ closedByEnter = true;
send(cm);
}
@@ -241,8 +243,16 @@ namespace mwmp
}
+ void GUIChat::closeInput()
+ {
+ mCommandLine->setCaption("");
+ setEditState(false);
+ }
+
void GUIChat::update(float dt)
{
+ closedByEnter = false;
+
if (windowState == CHAT_HIDDENMODE && !editState && isVisible())
{
curTime += dt;
diff --git a/apps/openmw/mwmp/GUI/GUIChat.hpp b/apps/openmw/mwmp/GUI/GUIChat.hpp
index 01e9626..60d7916 100644
--- a/apps/openmw/mwmp/GUI/GUIChat.hpp
+++ b/apps/openmw/mwmp/GUI/GUIChat.hpp
@@ -80,6 +80,20 @@ namespace mwmp
int windowState;
bool editState;
+ /// Isowind: the chat's input was just closed by Enter (sending, or with nothing typed); that same key press
+ /// mustn't open it again (takeClosedByEnter)
+ bool closedByEnter = false;
+
+ public:
+ /// Closes the input line (Escape while typing)
+ void closeInput();
+
+ bool takeClosedByEnter()
+ {
+ const bool closed = closedByEnter;
+ closedByEnter = false;
+ return closed;
+ }
float delay;
float curTime;
};
diff --git a/apps/openmw/mwmp/GUIController.cpp b/apps/openmw/mwmp/GUIController.cpp
index 0f0a0e4..3b308c2 100644
--- a/apps/openmw/mwmp/GUIController.cpp
+++ b/apps/openmw/mwmp/GUIController.cpp
@@ -219,6 +219,12 @@ bool mwmp::GUIController::pressedKey(int key)
MWBase::WindowManager *windowManager = MWBase::Environment::get().getWindowManager();
if (mChat == nullptr || windowManager->isConsoleMode() || windowManager->getMode() != MWGui::GM_None)
return false;
+ // Isowind: Escape while typing closes the chat's input line, not opens the menu
+ if (key == SDL_SCANCODE_ESCAPE && mChat->editState)
+ {
+ mChat->closeInput();
+ return true;
+ }
if (key == keyChatMode)
{
mChat->pressedChatMode();
@@ -226,6 +232,9 @@ bool mwmp::GUIController::pressedKey(int key)
}
else if (key == keySay)
{
+ // The Enter that just sent a message (or closed the empty input) doesn't open it again
+ if (mChat->takeClosedByEnter())
+ return true;
if (mMenuWasOpen)
return false;
mChat->pressedSay();
diff --git a/isowind/README.txt b/isowind/README.txt
index 599ce63..99e16af 100644
--- a/isowind/README.txt
+++ b/isowind/README.txt
@@ -51,7 +51,7 @@ Hosting a server
- 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,
- tough ones 15, bosses 60 ("Enemy respawns" speeds that up or slows it down). Plants and ore
+ 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.
- 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.
@@ -72,6 +72,15 @@ Enter Talk in the chat; F2 hides or shows the chat window.
The world never pauses, not even in menus. Saving and loading are off: the server keeps everything.
When you die you wake up at the nearest temple.
+Parties (MMO servers): players in a party share their quests as on a co-op server - journal,
+topics, quest progress, kill credit and what quests change in the world - while each keeps their
+own loot. Type in the chat:
+ /party invite NAME invite a player (their name, or the number before it in the player list)
+ /party accept join the party you were invited to (or /party decline)
+ /party who is in your party
+ /p MESSAGE talk to your party
+ /party leave leave it; you keep the quests you have
+
Looks
-----
Pixel art The world is drawn at low resolution with chunky pixels, retro textures, banded light
diff --git a/isowind/linux/isowind.sh b/isowind/linux/isowind.sh
index dc48dbb..3f958a7 100755
--- a/isowind/linux/isowind.sh
+++ b/isowind/linux/isowind.sh
@@ -132,7 +132,7 @@ ask_host_settings() {
"$(get_server_setting Isowind difficulty 0)" '-?[0-9]{1,3}'
set_setting "$FILE" Isowind difficulty "$REPLY"
if [ "$MODE" = mmo ]; then
- ask "How fast enemies come back: 0.5, 1, 2 or 4 (1: 1.5 minutes for the weakest, 60 for bosses)" \
+ ask "How fast enemies come back: 0.5, 1, 2 or 4 (1: 1.5 minutes for the weakest, 20 for bosses)" \
"$(get_server_setting Isowind respawnSpeed 1)" '0\.5|1|2|4'
set_setting "$FILE" Isowind respawnSpeed "$REPLY"
fi
diff --git a/isowind/server/CoreScripts/scripts/custom/isowindMmo.lua b/isowind/server/CoreScripts/scripts/custom/isowindMmo.lua
index 4b0b048..6d1a979 100644
--- a/isowind/server/CoreScripts/scripts/custom/isowindMmo.lua
+++ b/isowind/server/CoreScripts/scripts/custom/isowindMmo.lua
@@ -8,7 +8,7 @@
-- 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
--- tough they were (WoW-like tiers, from their health): trash 1.5 minutes, normal 5, elite 15, bosses 60, divided by
+-- 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.
@@ -33,10 +33,13 @@ local tiers = {
{ name = "trash", maxHealth = 60, minutes = 1.5 },
{ name = "normal", maxHealth = 200, minutes = 5 },
{ name = "elite", maxHealth = 500, minutes = 15 },
- { name = "boss", minutes = 60 }
+ { name = "boss", minutes = 20 }
}
-- Bosses whatever their health
local bossPatterns = { "^dagoth", "^vivec_god", "^almalexia", "^karstaag", "^lich_", "^heart_akulakhan" }
+-- Weak creatures, for when their health never reached the server (killed in a hit or two)
+local trashPatterns = { "^rat", "mudcrab", "scrib", "kwama forager", "cliff racer", "slaughterfish", "^nix",
+ "^skeleton", "ancestor_ghost", "^guar" }
local CHECK_SECONDS = 10
@@ -56,6 +59,27 @@ local function playerKey(pid)
return string.lower(Players[pid].accountName)
end
+-- Whose world a player's quest scripts change: theirs, or their whole party's (isowindParty.lua)
+local function questSharers(pid)
+ local name = playerKey(pid)
+ if IsowindParty ~= nil then
+ return IsowindParty.GetMemberNames(name)
+ end
+ return { name }
+end
+
+-- The pids of the others among names who are on
+local function otherOnlinePids(pid, names)
+ local pids = {}
+ for otherPid, player in pairs(Players) do
+ if otherPid ~= pid and player:IsLoggedIn() and
+ tableHelper.containsValue(names, string.lower(player.accountName)) then
+ table.insert(pids, otherPid)
+ end
+ end
+ return pids
+end
+
local function splitIndex(uniqueIndex)
local parts = uniqueIndex:split("-")
return tonumber(parts[1]), tonumber(parts[2])
@@ -242,17 +266,26 @@ local function onObjectDelete(eventStatus, pid, cellDescription, objects)
return
end
- local name = playerKey(pid)
+ -- A quest's deletion is the whole party's; a pickup only the player's
+ local names = fromScript and questSharers(pid) or { playerKey(pid) }
cell.data.isowindTaken = cell.data.isowindTaken or {}
- tes3mp.ClearObjectList()
- tes3mp.SetObjectListPid(pid)
- tes3mp.SetObjectListCell(cellDescription)
for uniqueIndex, object in pairs(mine) do
cell.data.isowindTaken[uniqueIndex] = cell.data.isowindTaken[uniqueIndex] or {}
- cell.data.isowindTaken[uniqueIndex][name] = true
- packetBuilder.AddObjectDelete(uniqueIndex, object)
+ for _, name in ipairs(names) do
+ cell.data.isowindTaken[uniqueIndex][name] = true
+ end
+ end
+ local recipients = otherOnlinePids(pid, names)
+ table.insert(recipients, pid)
+ for _, recipient in ipairs(recipients) do
+ tes3mp.ClearObjectList()
+ tes3mp.SetObjectListPid(recipient)
+ tes3mp.SetObjectListCell(cellDescription)
+ for uniqueIndex, object in pairs(mine) do
+ packetBuilder.AddObjectDelete(uniqueIndex, object)
+ end
+ tes3mp.SendObjectDelete(false)
end
- tes3mp.SendObjectDelete(false)
-- The rest as the default handler does
if next(shared) ~= nil then
@@ -263,7 +296,7 @@ local function onObjectDelete(eventStatus, pid, cellDescription, objects)
return customEventHooks.makeEventStatus(false, true)
end
--- A quest script enabling or disabling one of the game's own people or things: for that player only
+-- A quest script enabling or disabling one of the game's own people or things: for that player (and their party) only
local function onObjectState(eventStatus, pid, cellDescription, objects)
if eventStatus.validDefaultHandler == false or not isFromScript(tes3mp.GetObjectListOrigin()) then
return
@@ -286,13 +319,25 @@ local function onObjectState(eventStatus, pid, cellDescription, objects)
return
end
- local name = playerKey(pid)
+ local names = questSharers(pid)
cell.data.isowindStates = cell.data.isowindStates or {}
for uniqueIndex, object in pairs(mine) do
local record = cell.data.isowindStates[uniqueIndex] or { refId = object.refId, players = {} }
- record.players[name] = object.state
+ for _, name in ipairs(names) do
+ record.players[name] = object.state
+ end
cell.data.isowindStates[uniqueIndex] = record
end
+ -- The party's others who are on see it now (the player's own game already made the change)
+ for _, recipient in ipairs(otherOnlinePids(pid, names)) do
+ tes3mp.ClearObjectList()
+ tes3mp.SetObjectListPid(recipient)
+ tes3mp.SetObjectListCell(cellDescription)
+ for uniqueIndex, object in pairs(mine) do
+ packetBuilder.AddObjectState(uniqueIndex, object)
+ end
+ tes3mp.SendObjectState(false)
+ end
-- The rest as the default handler does
if next(shared) ~= nil then
@@ -477,6 +522,11 @@ local function respawnMinutes(refId, objectData)
end
local health = objectData ~= nil and objectData.stats ~= nil and objectData.stats.healthBase or nil
if health == nil then
+ for _, pattern in ipairs(trashPatterns) do
+ if refId:find(pattern) then
+ return tiers[1].minutes
+ end
+ end
return tiers[2].minutes
end
for _, tier in ipairs(tiers) do
diff --git a/isowind/server/CoreScripts/scripts/custom/isowindParty.lua b/isowind/server/CoreScripts/scripts/custom/isowindParty.lua
new file mode 100644
index 0000000..a772199
--- /dev/null
+++ b/isowind/server/CoreScripts/scripts/custom/isowindParty.lua
@@ -0,0 +1,460 @@
+-- Isowind MMO parties: players in a party share their quests as in co-op - journal, topics, quest variables, kill
+-- credit and what quest scripts do to the world (isowindMmo.lua asks GetMemberNames) - while loot stays each one's own.
+-- Members are also made allies (TES3MP's alliances: their followers don't fight each other).
+--
+-- /party who is in your party
+-- /party invite <name or id> invite a player (the number before their name in the player list works too)
+-- /party accept / decline answer an invitation
+-- /party leave leave your party
+-- /p <message> talk to your party
+--
+-- Kept in the world's data (isowindParties): members, and the party's journal, topics and quest variables, so
+-- members who were offline catch up when they log in.
+
+if not IsowindHost.IsMmo() then
+ return
+end
+
+IsowindParty = {}
+
+local MAX_MEMBERS = 8
+local INVITE_SECONDS = 120
+local invites = {} -- invited player's name -> { from = inviter's name, time = os.time() }
+
+local function lower(name)
+ return string.lower(name)
+end
+
+local function nameOf(pid)
+ return lower(Players[pid].accountName)
+end
+
+local function parties()
+ WorldInstance.data.isowindParties = WorldInstance.data.isowindParties or { nextId = 1, list = {} }
+ return WorldInstance.data.isowindParties
+end
+
+local function partyOf(name)
+ for id, party in pairs(parties().list) do
+ if tableHelper.containsValue(party.members, name) then
+ return id, party
+ end
+ end
+end
+
+local function onlinePid(name)
+ for pid, player in pairs(Players) do
+ if player:IsLoggedIn() and lower(player.accountName) == name then
+ return pid
+ end
+ end
+end
+
+local function message(pid, text)
+ tes3mp.SendMessage(pid, color.Orange .. "[Party] " .. color.White .. text .. "\n", false)
+end
+
+local function tellParty(party, text, exceptName)
+ for _, member in ipairs(party.members) do
+ local pid = onlinePid(member)
+ if pid ~= nil and member ~= exceptName then
+ message(pid, text)
+ end
+ end
+end
+
+-- Everyone a player's quest progress goes to: their party, or just them
+function IsowindParty.GetMemberNames(name)
+ local _, party = partyOf(name)
+ if party ~= nil then
+ return party.members
+ end
+ return { name }
+end
+
+-- --- Sharing ----------------------------------------------------------------------------------------------------
+
+local function journalKey(item)
+ return tostring(item.type) .. "|" .. lower(item.quest) .. "|" .. tostring(item.index)
+end
+
+local function isQuestVariable(id)
+ return tableHelper.containsCaseInsensitiveString(clientVariableScopes.globals.quest, id)
+end
+
+-- Journal entries a member doesn't have yet: saved for them, and sent if they're on
+local function giveJournal(player, items)
+ player.data.journal = player.data.journal or {}
+ local have = {}
+ for _, item in ipairs(player.data.journal) do
+ have[journalKey(item)] = true
+ end
+ local missing = {}
+ for _, item in ipairs(items) do
+ if not have[journalKey(item)] then
+ have[journalKey(item)] = true
+ table.insert(missing, item)
+ end
+ end
+ if #missing == 0 then
+ return
+ end
+ stateHelper:SaveJournal(player, { journal = missing })
+ if player:IsLoggedIn() then
+ tes3mp.ClearJournalChanges(player.pid)
+ for _, item in ipairs(missing) do
+ if item.type == enumerations.journal.ENTRY then
+ local timestamp = item.timestamp or WorldInstance.data.time
+ tes3mp.AddJournalEntryWithTimestamp(player.pid, item.quest, item.index, item.actorRefId or "player",
+ timestamp.daysPassed, timestamp.month, timestamp.day)
+ else
+ tes3mp.AddJournalIndex(player.pid, item.quest, item.index)
+ end
+ end
+ tes3mp.SendJournalChanges(player.pid)
+ end
+end
+
+local function giveTopics(player, topics)
+ player.data.topics = player.data.topics or {}
+ local missing = {}
+ for _, topic in ipairs(topics) do
+ if not tableHelper.containsValue(player.data.topics, topic) then
+ table.insert(player.data.topics, topic)
+ table.insert(missing, topic)
+ end
+ end
+ if #missing == 0 then
+ return
+ end
+ player:QuicksaveToDrive()
+ if player:IsLoggedIn() then
+ tes3mp.ClearTopicChanges(player.pid)
+ for _, topic in ipairs(missing) do
+ tes3mp.AddTopic(player.pid, topic)
+ end
+ tes3mp.SendTopicChanges(player.pid)
+ end
+end
+
+local function giveVariables(player, variables)
+ if next(variables) == nil then
+ return
+ end
+ stateHelper:SaveClientScriptGlobal(player, variables)
+ if player:IsLoggedIn() then
+ tes3mp.ClearClientGlobals()
+ for id, variable in pairs(variables) do
+ if variable.variableType == enumerations.variableType.FLOAT then
+ tes3mp.AddClientGlobalFloat(id, variable.floatValue)
+ else
+ tes3mp.AddClientGlobalInteger(id, variable.intValue, variable.variableType)
+ end
+ end
+ tes3mp.SendClientScriptGlobal(player.pid)
+ end
+end
+
+local function addToPartyJournal(party, items)
+ local have = {}
+ for _, item in ipairs(party.journal) do
+ have[journalKey(item)] = true
+ end
+ for _, item in ipairs(items) do
+ if not have[journalKey(item)] then
+ have[journalKey(item)] = true
+ table.insert(party.journal, item)
+ end
+ end
+end
+
+-- The other members who are on
+local function forOtherMembers(party, name, callback)
+ for _, member in ipairs(party.members) do
+ local pid = onlinePid(member)
+ if member ~= name and pid ~= nil then
+ callback(Players[pid])
+ end
+ end
+end
+
+local function onJournal(eventStatus, pid, playerPacket)
+ local _, party = partyOf(nameOf(pid))
+ if party == nil or playerPacket == nil or playerPacket.journal == nil then
+ return
+ end
+ addToPartyJournal(party, playerPacket.journal)
+ forOtherMembers(party, nameOf(pid), function(member) giveJournal(member, playerPacket.journal) end)
+ WorldInstance:QuicksaveToDrive()
+end
+
+local function onTopic(eventStatus, pid)
+ local _, party = partyOf(nameOf(pid))
+ if party == nil then
+ return
+ end
+ local topics = {}
+ for i = 0, tes3mp.GetTopicChangesSize(pid) - 1 do
+ local topic = tes3mp.GetTopicId(pid, i)
+ table.insert(topics, topic)
+ if not tableHelper.containsValue(party.topics, topic) then
+ table.insert(party.topics, topic)
+ end
+ end
+ forOtherMembers(party, nameOf(pid), function(member) giveTopics(member, topics) end)
+ WorldInstance:QuicksaveToDrive()
+end
+
+local function onVariables(eventStatus, pid, variables)
+ local _, party = partyOf(nameOf(pid))
+ if party == nil or variables == nil then
+ return
+ end
+ local shared = {}
+ for id, variable in pairs(variables) do
+ if isQuestVariable(id) then
+ shared[id] = variable
+ party.variables[id] = variable
+ end
+ end
+ if next(shared) == nil then
+ return
+ end
+ forOtherMembers(party, nameOf(pid), function(member) giveVariables(member, shared) end)
+ WorldInstance:QuicksaveToDrive()
+end
+
+-- A member logging in catches up with what the party did meanwhile
+local function onLogin(eventStatus, pid)
+ if Players[pid] == nil or not Players[pid]:IsLoggedIn() then
+ return
+ end
+ local _, party = partyOf(nameOf(pid))
+ if party == nil then
+ return
+ end
+ local player = Players[pid]
+ giveJournal(player, party.journal)
+ giveTopics(player, party.topics)
+ giveVariables(player, party.variables)
+ tellParty(party, Players[pid].accountName .. " is here.", nameOf(pid))
+end
+
+-- --- Allies -----------------------------------------------------------------------------------------------------
+
+local function setAllied(player, otherName, allied)
+ player.data.alliedPlayers = player.data.alliedPlayers or {}
+ local index = nil
+ for i, name in ipairs(player.data.alliedPlayers) do
+ if lower(name) == otherName then
+ index = i
+ end
+ end
+ if allied and index == nil then
+ table.insert(player.data.alliedPlayers, otherName)
+ elseif not allied and index ~= nil then
+ table.remove(player.data.alliedPlayers, index)
+ end
+ player:QuicksaveToDrive()
+ if player:IsLoggedIn() then
+ player:LoadAllies()
+ end
+end
+
+-- --- Joining and leaving ----------------------------------------------------------------------------------------
+
+-- The quest variables a player has that parties share
+local function questVariablesOf(player)
+ local variables = {}
+ local globals = player.data.clientVariables and player.data.clientVariables.globals or {}
+ for id, variable in pairs(globals) do
+ if type(variable) == "table" and isQuestVariable(id) then
+ variables[id] = variable
+ end
+ end
+ return variables
+end
+
+local function join(pid, inviterName)
+ local name = nameOf(pid)
+ local player = Players[pid]
+ local inviterPid = onlinePid(inviterName)
+ local id, party = partyOf(inviterName)
+
+ if party == nil then
+ if inviterPid == nil then
+ message(pid, "They've left; ask them to invite you again.")
+ return
+ end
+ local inviter = Players[inviterPid]
+ local data = parties()
+ id = tostring(data.nextId)
+ data.nextId = data.nextId + 1
+ party = { members = { inviterName }, journal = {}, topics = {}, variables = {} }
+ addToPartyJournal(party, inviter.data.journal or {})
+ for _, topic in ipairs(inviter.data.topics or {}) do
+ table.insert(party.topics, topic)
+ end
+ party.variables = questVariablesOf(inviter)
+ data.list[id] = party
+ end
+
+ if #party.members >= MAX_MEMBERS then
+ message(pid, "That party is full (" .. MAX_MEMBERS .. ").")
+ return
+ end
+
+ -- Both sides get what the other has done
+ local newJournal = player.data.journal or {}
+ local newTopics = player.data.topics or {}
+ local newVariables = questVariablesOf(player)
+ for variableId, variable in pairs(newVariables) do
+ if party.variables[variableId] ~= nil then
+ newVariables[variableId] = nil
+ else
+ party.variables[variableId] = variable
+ end
+ end
+
+ forOtherMembers(party, name, function(member)
+ giveJournal(member, newJournal)
+ giveTopics(member, newTopics)
+ giveVariables(member, newVariables)
+ setAllied(member, player.accountName, true)
+ setAllied(player, member.accountName, true)
+ end)
+ addToPartyJournal(party, newJournal)
+ for _, topic in ipairs(newTopics) do
+ if not tableHelper.containsValue(party.topics, topic) then
+ table.insert(party.topics, topic)
+ end
+ end
+ table.insert(party.members, name)
+
+ giveJournal(player, party.journal)
+ giveTopics(player, party.topics)
+ giveVariables(player, party.variables)
+
+ WorldInstance:QuicksaveToDrive()
+ tellParty(party, player.accountName .. " joined the party.", name)
+ message(pid, "You joined the party. Its quests are now yours too. /p talks to it, /party leave leaves it.")
+end
+
+local function leave(pid)
+ local name = nameOf(pid)
+ local id, party = partyOf(name)
+ if party == nil then
+ message(pid, "You're not in a party.")
+ return
+ end
+ tableHelper.removeValue(party.members, name)
+ tableHelper.cleanNils(party.members)
+ forOtherMembers(party, name, function(member)
+ setAllied(member, name, false)
+ setAllied(Players[pid], lower(member.accountName), false)
+ end)
+ tellParty(party, Players[pid].accountName .. " left the party.", name)
+ if #party.members <= 1 then
+ tellParty(party, "The party is over.", name)
+ parties().list[id] = nil
+ end
+ WorldInstance:QuicksaveToDrive()
+ message(pid, "You left the party. You keep the quests you have.")
+end
+
+-- --- Commands ---------------------------------------------------------------------------------------------------
+
+local function findPlayer(text)
+ local number = tonumber(text)
+ if number ~= nil and Players[number] ~= nil and Players[number]:IsLoggedIn() then
+ return number
+ end
+ return onlinePid(lower(text or ""))
+end
+
+local function partyCommand(pid, cmd)
+ local action = cmd[2] and lower(cmd[2]) or ""
+ local name = nameOf(pid)
+
+ if action == "invite" then
+ local targetText = tableHelper.concatenateFromIndex(cmd, 3, " ")
+ local targetPid = findPlayer(targetText)
+ if targetPid == nil then
+ message(pid, "No one called " .. tostring(targetText) .. " is on. Use their name or their number.")
+ elseif targetPid == pid then
+ message(pid, "That's you.")
+ elseif partyOf(nameOf(targetPid)) ~= nil then
+ message(pid, Players[targetPid].accountName .. " is already in a party.")
+ else
+ local _, party = partyOf(name)
+ if party ~= nil and #party.members >= MAX_MEMBERS then
+ message(pid, "Your party is full (" .. MAX_MEMBERS .. ").")
+ return
+ end
+ invites[nameOf(targetPid)] = { from = name, time = os.time() }
+ message(pid, "You invited " .. Players[targetPid].accountName .. ".")
+ message(targetPid, Players[pid].accountName .. " invites you to their party, to do quests together: " ..
+ color.Yellow .. "/party accept" .. color.White .. " or " .. color.Yellow .. "/party decline")
+ end
+
+ elseif action == "accept" or action == "decline" then
+ local invite = invites[name]
+ invites[name] = nil
+ if invite == nil or os.time() - invite.time > INVITE_SECONDS then
+ message(pid, "You have no invitation waiting.")
+ elseif action == "decline" then
+ message(pid, "You declined.")
+ local inviterPid = onlinePid(invite.from)
+ if inviterPid ~= nil then
+ message(inviterPid, Players[pid].accountName .. " declined.")
+ end
+ elseif partyOf(name) ~= nil then
+ message(pid, "Leave your party first (/party leave).")
+ else
+ join(pid, invite.from)
+ end
+
+ elseif action == "leave" then
+ leave(pid)
+
+ else
+ local _, party = partyOf(name)
+ if party == nil then
+ message(pid, "You're not in a party. " .. color.Yellow .. "/party invite <name>" .. color.White ..
+ " invites someone; a party shares quests, and each of you keeps your own loot.")
+ else
+ local list = {}
+ for _, member in ipairs(party.members) do
+ table.insert(list, member .. (onlinePid(member) and "" or " (away)"))
+ end
+ message(pid, "Your party: " .. table.concat(list, ", ") .. ". " .. color.Yellow .. "/p <message>" ..
+ color.White .. " talks to it, " .. color.Yellow .. "/party leave" .. color.White .. " leaves it.")
+ end
+ end
+end
+
+local function partyChat(pid, cmd)
+ local _, party = partyOf(nameOf(pid))
+ local text = tableHelper.concatenateFromIndex(cmd, 2, " ")
+ if party == nil then
+ message(pid, "You're not in a party.")
+ elseif text ~= nil and text ~= "" then
+ for _, member in ipairs(party.members) do
+ local memberPid = onlinePid(member)
+ if memberPid ~= nil then
+ tes3mp.SendMessage(memberPid, color.Orange .. "[Party] " .. Players[pid].accountName .. ": " ..
+ color.White .. text .. "\n", false)
+ end
+ end
+ end
+end
+
+customCommandHooks.registerCommand("party", partyCommand)
+customCommandHooks.registerCommand("p", partyChat)
+
+customEventHooks.registerHandler("OnPlayerJournal", onJournal)
+customEventHooks.registerHandler("OnPlayerTopic", onTopic)
+customEventHooks.registerHandler("OnClientScriptGlobal", onVariables)
+customEventHooks.registerHandler("OnPlayerFinishLogin", onLogin)
+
+return IsowindParty
diff --git a/isowind/server/CoreScripts/scripts/customScripts.lua b/isowind/server/CoreScripts/scripts/customScripts.lua
index f8e9148..dc27093 100644
--- a/isowind/server/CoreScripts/scripts/customScripts.lua
+++ b/isowind/server/CoreScripts/scripts/customScripts.lua
@@ -8,3 +8,4 @@
require("custom/isowindHost")
require("custom/isowindMmo")
+require("custom/isowindParty")
diff --git a/isowind/server/tes3mp-server-default.cfg b/isowind/server/tes3mp-server-default.cfg
index 6eca2c8..4ffa3f3 100644
--- a/isowind/server/tes3mp-server-default.cfg
+++ b/isowind/server/tes3mp-server-default.cfg
@@ -18,7 +18,7 @@ mode = coop
pvp = false
# -100 (very easy) to 100 (very hard); 0 is Morrowind's normal
difficulty = 0
-# MMO: how much faster than normal enemies come back (normal: 1.5 minutes for the weakest to 60 for bosses)
+# MMO: how much faster than normal enemies come back (normal: 1.5 minutes for the weakest to 20 for bosses)
respawnSpeed = 1
# How much faster than Morrowind's the time of day goes (Morrowind's: an hour in 2 minutes)
timeSpeed = 1
diff --git a/isowind/server/tests/mmotest.lua b/isowind/server/tests/mmotest.lua
index b5082ee..b962f68 100644
--- a/isowind/server/tests/mmotest.lua
+++ b/isowind/server/tests/mmotest.lua
@@ -1,6 +1,6 @@
--- How to run: copy this into a copy of the server folder as CoreScripts/scripts/custom/mmotest.lua, add
+-- How to run: copy this into a copy of the server folder as CoreScripts/scripts/custom/, add
-- require("custom/mmotest") at the end of customScripts.lua, put mode = mmo under [Isowind] in tes3mp-server.cfg and
--- start tes3mp-server for a few seconds; the log shows "[mmotest] PASS/FAIL ..." and "done, N failed".
+-- start tes3mp-server for a few seconds; the log shows PASS/FAIL lines and "done, N failed".
-- Tests of isowindMmo.lua inside a real server: fake players and packets, real cells and world data.
local log = function(text) tes3mp.LogMessage(enumerations.log.INFO, "[mmotest] " .. text) end
local failures = 0
@@ -171,8 +171,8 @@ local function runTests()
customEventHooks.triggerHandlers("OnActorDeath", customEventHooks.makeEventStatus(true, true),
{ pid, CELL, { ["998-0"] = { refId = "dagoth gares", killer = {} },
["997-0"] = { refId = "ordinator", killer = {} } } })
- check("Dagoth is a boss (60 minutes)",
- math.abs(WorldInstance.data.isowindRespawns[CELL]["998-0"] - os.time() - 3600) <= 2)
+ check("Dagoth is a boss (20 minutes)",
+ math.abs(WorldInstance.data.isowindRespawns[CELL]["998-0"] - os.time() - 1200) <= 2)
check("250 health is elite (15 minutes)",
math.abs(WorldInstance.data.isowindRespawns[CELL]["997-0"] - os.time() - 900) <= 2)
@@ -204,6 +204,13 @@ local function runTests()
local refused = lastSent("SetContainerItemActionCountByIndex")
check("take of something known not to be there still refused", refused ~= nil and refused.args[3] == 0)
+ -- A rat killed before its health reached the server is still trash
+ cell.data.objectData["995-0"] = { refId = "Rat" }
+ customEventHooks.triggerHandlers("OnActorDeath", customEventHooks.makeEventStatus(true, true),
+ { pid, CELL, { ["995-0"] = { refId = "Rat", killer = {} } } })
+ check("rat with unknown health is trash (90 seconds)",
+ math.abs(WorldInstance.data.isowindRespawns[CELL]["995-0"] - os.time() - 90) <= 2)
+
-- One a quest script disabled after it died
cell.data.objectData["996-0"] = { refId = "quest_npc", state = false, stats = { healthBase = 40 } }
customEventHooks.triggerHandlers("OnActorDeath", customEventHooks.makeEventStatus(true, true),
diff --git a/isowind/server/tests/partytest.lua b/isowind/server/tests/partytest.lua
new file mode 100644
index 0000000..2e5ed36
--- /dev/null
+++ b/isowind/server/tests/partytest.lua
@@ -0,0 +1,169 @@
+-- How to run: copy this into a copy of the server folder as CoreScripts/scripts/custom/, add
+-- require("custom/partytest") at the end of customScripts.lua, put mode = mmo under [Isowind] in tes3mp-server.cfg and
+-- start tes3mp-server for a few seconds; the log shows PASS/FAIL lines and "done, N failed".
+-- Tests of isowindParty.lua inside a real server: two fake players, real world data.
+local log = function(text) tes3mp.LogMessage(enumerations.log.INFO, "[partytest] " .. text) end
+local failures = 0
+local function check(name, condition)
+ if condition then log("PASS " .. name) else log("FAIL " .. name); failures = failures + 1 end
+end
+
+local sent = {}
+local current = {}
+local function installMocks()
+ for name, fn in pairs(tes3mp) do
+ if type(name) == "string" and (name:find("^Set") or name:find("^Add") or name:find("^Send") or
+ name:find("^Clear") or name == "CopyReceivedObjectListToStore") then
+ tes3mp[name] = function(...)
+ local args = { ... }
+ if name == "ClearObjectList" then current = { objects = {} }
+ elseif name == "SetObjectRefNum" then current.refNum = args[1]
+ elseif name == "SetObjectState" then current.state = args[1]
+ elseif name == "AddObject" then table.insert(current.objects, { refNum = current.refNum, state = current.state })
+ elseif name == "SetObjectListPid" then current.pid = args[1]
+ elseif name:find("^Send") then
+ table.insert(sent, { name = name, args = args, pid = current.pid, objects = current.objects })
+ end
+ end
+ end
+ end
+ current = { objects = {} }
+end
+
+local topicChanges = {}
+local function sentTo(name, pid)
+ for _, packet in ipairs(sent) do
+ if packet.name == name and (packet.args[1] == pid or packet.pid == pid) then return packet end
+ end
+end
+local function messagesTo(pid)
+ local texts = {}
+ for _, packet in ipairs(sent) do
+ if packet.name == "SendMessage" and packet.args[1] == pid then table.insert(texts, packet.args[2]) end
+ end
+ return table.concat(texts, " | ")
+end
+local function hasJournal(player, quest, index)
+ for _, item in ipairs(player.data.journal or {}) do
+ if item.quest == quest and item.index == index then return true end
+ end
+ return false
+end
+local function makePlayer(pid, name, journal)
+ local player = { pid = pid, accountName = name, name = name, consoleCommandsQueued = {}, summons = {},
+ alliesLoaded = 0,
+ data = { location = { cell = "-3, 6" }, alliedPlayers = {}, journal = journal, topics = {},
+ clientVariables = { globals = {} }, customVariables = {} } }
+ player.IsLoggedIn = function() return true end
+ player.QuicksaveToDrive = function() end
+ player.Save = function() end
+ player.Message = function() end
+ player.LoadAllies = function(self) self.alliesLoaded = self.alliesLoaded + 1 end
+ Players[pid] = player
+ return player
+end
+local function command(pid, text)
+ local cmd = text:split(" ")
+ customCommandHooks.getCallback(cmd[1])(pid, cmd)
+end
+
+local function runTests()
+ installMocks()
+ tes3mp.GetTopicChangesSize = function() return #topicChanges end
+ tes3mp.GetTopicId = function(pid, i) return topicChanges[i + 1] end
+ tes3mp.GetObjectListOrigin = function() return enumerations.packetOrigin.CLIENT_SCRIPT_LOCAL end
+ WorldInstance.data.isowindParties = nil
+ local ENTRY = enumerations.journal.ENTRY
+
+ local alpha = makePlayer(0, "Alpha", { { type = ENTRY, quest = "a1_1_findspymaster", index = 1, actorRefId = "x" } })
+ local beta = makePlayer(1, "Beta", { { type = ENTRY, quest = "mg_guildmanual", index = 10, actorRefId = "y" } })
+ beta.data.clientVariables.globals.hortatorvotes = { variableType = enumerations.variableType.SHORT, intValue = 2 }
+
+ -- Invite and accept
+ command(0, "party invite Beta")
+ check("Beta is told of the invitation", messagesTo(1):find("invites you") ~= nil)
+ command(1, "party accept")
+ local _, party = nil, nil
+ for id, p in pairs(WorldInstance.data.isowindParties.list) do party = p end
+ check("party has both", party ~= nil and #party.members == 2)
+ check("they're allies", #alpha.data.alliedPlayers == 1 and #beta.data.alliedPlayers == 1 and
+ alpha.alliesLoaded > 0 and beta.alliesLoaded > 0)
+ check("Beta got Alpha's journal", hasJournal(beta, "a1_1_findspymaster", 1))
+ check("Alpha got Beta's journal", hasJournal(alpha, "mg_guildmanual", 10))
+ check("Alpha got Beta's quest variable", alpha.data.clientVariables.globals.hortatorvotes ~= nil and
+ alpha.data.clientVariables.globals.hortatorvotes.intValue == 2)
+ check("journals sent to both games", sentTo("SendJournalChanges", 0) ~= nil and sentTo("SendJournalChanges", 1) ~= nil)
+
+ -- A new journal entry reaches the other member, once
+ sent = {}
+ local item = { type = ENTRY, quest = "a1_2_antabolis", index = 5, actorRefId = "z" }
+ customEventHooks.triggerHandlers("OnPlayerJournal", customEventHooks.makeEventStatus(true, true),
+ { 0, { journal = { item } } })
+ check("new entry given to Beta", hasJournal(beta, "a1_2_antabolis", 5) and sentTo("SendJournalChanges", 1) ~= nil)
+ check("not sent back to Alpha", sentTo("SendJournalChanges", 0) == nil)
+ local count = 0
+ customEventHooks.triggerHandlers("OnPlayerJournal", customEventHooks.makeEventStatus(true, true),
+ { 0, { journal = { item } } })
+ for _, j in ipairs(beta.data.journal) do if j.quest == "a1_2_antabolis" then count = count + 1 end end
+ check("same entry not given twice", count == 1)
+
+ -- Topics
+ sent = {}
+ topicChanges = { "latest rumors" }
+ customEventHooks.triggerHandlers("OnPlayerTopic", customEventHooks.makeEventStatus(true, true), { 1 })
+ check("topic given to Alpha", tableHelper.containsValue(alpha.data.topics, "latest rumors") and
+ sentTo("SendTopicChanges", 0) ~= nil)
+
+ -- Quest variables, but not others
+ sent = {}
+ customEventHooks.triggerHandlers("OnClientScriptGlobal", customEventHooks.makeEventStatus(true, true),
+ { 0, { heartdestroyed = { variableType = enumerations.variableType.SHORT, intValue = 1 },
+ npcvoicedistance = { variableType = enumerations.variableType.FLOAT, floatValue = 750 } } })
+ check("quest variable given to Beta", beta.data.clientVariables.globals.heartdestroyed ~= nil)
+ check("other variables not", beta.data.clientVariables.globals.npcvoicedistance == nil)
+
+ -- A quest script disabling someone: the whole party
+ logicHandler.LoadCell("-3, 6")
+ local cell = LoadedCells["-3, 6"]
+ sent = {}
+ customEventHooks.triggerValidators("OnObjectState", { 0, "-3, 6", { ["7777-0"] = { refId = "quest_npc",
+ uniqueIndex = "7777-0", state = false } }, {} })
+ local record = cell.data.isowindStates["7777-0"]
+ check("quest disable kept for both members", record.players.alpha == false and record.players.beta == false)
+ local toBeta = sentTo("SendObjectState", 1)
+ check("Beta's game told now", toBeta ~= nil and toBeta.objects[1] ~= nil and toBeta.objects[1].state == false)
+ check("Alpha's game not told (it did it)", sentTo("SendObjectState", 0) == nil)
+
+ -- Kill credit for the ally
+ 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 = {} } } })
+ check("party member gets the kill", beta.data.kills ~= nil and beta.data.kills.mudcrab == 1)
+
+ -- Catching up at login
+ sent = {}
+ table.insert(party.journal, { type = ENTRY, quest = "tg_loyalty", index = 30, actorRefId = "w" })
+ customEventHooks.triggerHandlers("OnPlayerFinishLogin", customEventHooks.makeEventStatus(true, true), { 1 })
+ check("Beta catches up at login", hasJournal(beta, "tg_loyalty", 30))
+
+ -- Leaving
+ sent = {}
+ command(1, "party leave")
+ check("two-player party ends when one leaves", next(WorldInstance.data.isowindParties.list) == nil)
+ check("no longer allies", #alpha.data.alliedPlayers == 0 and #beta.data.alliedPlayers == 0)
+ check("Beta keeps the quests", hasJournal(beta, "a1_1_findspymaster", 1))
+
+ -- Alone again: a quest script is just theirs
+ customEventHooks.triggerValidators("OnObjectState", { 0, "-3, 6", { ["7778-0"] = { refId = "quest_npc2",
+ uniqueIndex = "7778-0", state = false } }, {} })
+ check("after leaving, quest changes are only one's own", cell.data.isowindStates["7778-0"].players.alpha == false
+ and cell.data.isowindStates["7778-0"].players.beta == nil)
+
+ log("done, " .. failures .. " failed")
+end
+
+customEventHooks.registerHandler("OnServerPostInit", function()
+ local ok, err = pcall(runTests)
+ if not ok then log("ERROR " .. tostring(err)) end
+end)