Skip to content

Commit

Permalink
fixes: comms, turn notification, reputation & artifacts on wh, kraylo…
Browse files Browse the repository at this point in the history
…r and exuari improved
  • Loading branch information
Pithlit committed Sep 16, 2024
1 parent c148931 commit acf08a7
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 19 deletions.
22 changes: 20 additions & 2 deletions eecs/campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from interfaces import storage
import json
import string
from datetime import datetime, timedelta
from threading import Timer

# load scenarios, that should be available in the campaign.
# use the complete filename without the folder.
Expand Down Expand Up @@ -113,12 +115,12 @@ def scenario_event(scenario: models.scenario.Scenario, crew: models.crew.Crew, e
# requests
elif event_topic == "request_reputation":
if details:
models.crew.getCrewByCallsign(details).sendReputation(reduce=True)
models.crew.getCrewByCallsign(details).sendReputation(server="localhost", reduce=True) # XXX server is hacky
else:
crew.sendReputation()
elif event_topic == "request_artifacts":
assert isinstance(details, str)
models.crew.getCrewByCallsign(details).sendArtifacts()
models.crew.getCrewByCallsign(details).sendArtifacts(server="localhost") # XXX server is hacky

# scenario specific
if s == "20_training1":
Expand Down Expand Up @@ -270,5 +272,21 @@ def scenario_event(scenario: models.scenario.Scenario, crew: models.crew.Crew, e
chiffre = cypher(msg, "exuari")
msg = "Wir haben eine Subraum-Übertragung aufgefangen:\n\n"+chiffre
outbound.pyroMessage.send("Fernschreiber", msg)
elif event_topic == "kraylor-comms":
msg = details
msg = "Wir haben eine Subraum-Übertragung aufgefangen:\n\n"+msg
outbound.pyroMessage.send("Fernschreiber", msg)
elif event_topic == "turn":
duration = details
until = datetime.now() + timedelta(seconds=duration)
until_human = until.strftime("%H:%M:%S")
outbound.stationsComms.turntime(f"Nächste Flottenbesprechung um {until_human}")
Timer(duration-5*60, outbound.stationsComms.turnwarning).start()
elif event_topic == "pause":
duration = details
until = datetime.now() + timedelta(seconds=duration)
until_human = until.strftime("%H:%M:%S")
outbound.stationsComms.turntime(f"Flottenbesprechung bis {until_human}")


core.subscribe("scenario_event", scenario_event)
16 changes: 12 additions & 4 deletions eecs/models/crew.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,12 @@ def hasArtifact(self, artifact_name):
def rmArtifact(self, artifact_name):
del self.artifacts[artifact_name]

def sendArtifacts(self):
def sendArtifacts(self, server=None):
"""send artifacts to server, granting them to the current ship"""
if not server:
_server = self.instance_name
else:
_server = server
amount = len(self.artifacts)
if amount <= 0:
return
Expand All @@ -265,14 +269,18 @@ def sendArtifacts(self):
_OBJECT_=getPlayerShip(-1)
_OBJECT_:addToShipLog("You carry {amount} artifact{"s" if amount > 1 else ""} from previous missions to deliver to the fleet command station.", "green")"""
script += script_artifacts
luaExecutor.exec(script, self.instance_name+":8080", 0, Crew._artifactCallback, [self])
luaExecutor.exec(script, _server+":8080", 0, Crew._artifactCallback, [self])

def _artifactCallback(self, success):
if success:
self.artifacts.clear()

def sendReputation(self, reduce=False):
def sendReputation(self, server=None, reduce=False):
"""send reputation bonus to server, granting it the current ship"""
if not server:
_server = self.instance_name
else:
_server = server
amount = self.getTotalReputationBonus(reduce)
log.info(f"{self.crew_name} requested {amount} reputation bonus to {self.instance_name}")
if amount <= 0:
Expand All @@ -282,7 +290,7 @@ def sendReputation(self, reduce=False):
_OBJECT_:addReputationPoints({amount})
_OBJECT_:addToShipLog("Reputation: +{amount} from previous missions", "green")
"""
luaExecutor.exec(script, self.instance_name+":8080", 1, Crew._repCallback, [self, reduce])
luaExecutor.exec(script, _server + ":8080", 1, Crew._repCallback, [self, reduce])

def _repCallback(self, reduce, success):
if success and reduce:
Expand Down
25 changes: 25 additions & 0 deletions eecs/outbound/stationsComms.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,31 @@ def sanitize_message(crew, what):
instance_name = lua.sanitize_lua_string(crew.instance_name)
return f"{crew_name} {what}", instance_name

def turntime(msg):
if not existing_subscription:
return
(station_server, station_name) = existing_subscription
color = "yellow"
script = f"""
local id=getPlayerShipIndex("{station_name}")
_OBJECT_=getPlayerShip(id)
_OBJECT_:addToShipLog("{msg}", "{color}")
_OBJECT_:addCustomInfo("ShipLog", "turntime", "{msg}", 1)"""
luaExecutor.exec(script, station_server+":8080", 1)

def turnwarning():
if not existing_subscription:
return
(station_server, station_name) = existing_subscription
color = "yellow"
msg = "Flottenbesprechung beginnt in 5 Minuten. Bitte Schiffe zurückrufen."
script = f"""
local id=getPlayerShipIndex("{station_name}")
_OBJECT_=getPlayerShip(id)
_OBJECT_:addToShipLog("{msg}", "{color}")"""
luaExecutor.exec(script, station_server+":8080", 1)


def backlog_append(crew, what, **kwargs):
msg, instance_name = sanitize_message(crew, what)
backlog.append((msg, instance_name))
Expand Down
14 changes: 7 additions & 7 deletions eecs/tools/fleetCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def helpMechanics():
d.msgbox("""Übersicht über die Spielmechaniken der Kampagne:
Reputation:
* Auf Trainins- und Einzelmissionen hat jede Crew ihr eingenes Reputaions-Konto für die entsprechende Mission. Die Reputation zum Ende einer Mission wird nicht in die nächste übernommen.
* Auf Trainings- und Einzelmissionen hat jede Crew ihr eigenes Reputations-Konto für die entsprechende Mission. Die Reputation zum Ende einer Mission wird nicht in die nächste übernommen.
* Während der Wurmloch-Expedition gibt es ein gemeinsames Reputations-Konto für die gesamte Flotte.
Reputations-Bonus:
Expand All @@ -102,7 +102,7 @@ def helpMechanics():
Artefakte:
* In jeder Trainings- und Einzelmission ist ein Artefakt versteckt, dass von einer Crew gescannt und eingesammelt werden kann.
* Um ein Artefakt einzusammeln, muss die Einfangfrequenz ermittelt werden, und die Schilde des Schiffs auf diese Frequenz kalibriert werden. Dann kann das Artefakt mit aktivierten Schilden eingesammelt werden. Ist die Frequenz falsch, oder die Schilde deaktivert, wird das Artefakt beim Einsammeln zerstört und hinterlässt Schaden am Schiff.
* Um ein Artefakt einzusammeln, muss die Einfangfrequenz ermittelt werden, und die Schilde des Schiffs auf diese Frequenz kalibriert werden. Dann kann das Artefakt mit aktivierten Schilden eingesammelt werden. Ist die Frequenz falsch, oder die Schilde deaktiviert, wird das Artefakt beim Einsammeln zerstört und hinterlässt Schaden am Schiff.
* Wird ein Artefakt eingesammelt, sind Details dazu im Schiffs-Log der Relay-Station zu sehen.
* Wurde ein Artefakt einer Mission einmal eingesammelt, bringt ein weiteres Einsammeln des selben Artefakts in einer Wiederholung der Mission keine Vorteile.
* Sobald ein Schiff auf der Wurmloch-Expedition an der Station des Flottenkommandos dockt, werden alle von der Crew gesammelten Artefakte automatisch übergeben.
Expand Down Expand Up @@ -211,12 +211,12 @@ def selectShips():
ship_dict = { # descr not used
"Adder MK7": "Scout, sehr schnell und wendig, schwach bewaffnet.",
"Phobos M3P": "Leichter Kreuzer, Allrounder, Standardschiff für unerfahrene Crews.",
"Hathcock": "Laser-Frigatte, spezialisiert gegen Jäger und leichte Torpedoschiffe.",
"Piranha M5P": "Raketen-Frigatte, spezialisiert gegen schwer gepanzerte Ziele.",
"Nautilus": "Minen-Frigatte, kann Minen legen.",
"Hathcock": "Laser-Fregatte, spezialisiert gegen Jäger und leichte Torpedoschiffe.",
"Piranha M5P": "Raketen-Fregatte, spezialisiert gegen schwer gepanzerte Ziele.",
"Nautilus": "Minen-Fregatte, kann Minen legen.",
"Atlantis": "Schwerer Kreuzer, Crew muss gut zusammenarbeiten. Standardschiff für Story-Missionen",
"Crucible": "Raketen-Corvette, schweres Schiff für Frontalangriffe.",
"Maverick": "Laser-Corvette, schweres Schiff mit Rundumverteidigung.",
"Crucible": "Raketen-Korvette, schweres Schiff für Frontalangriffe.",
"Maverick": "Laser-Korvette, schweres Schiff mit Rundumverteidigung.",
}
msg += """
Expand Down
6 changes: 3 additions & 3 deletions scripts-piglit/comms_station_sandbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -953,23 +953,23 @@ function improveStationService(improvements)
end
table.insert(comms_source.instant_energy,comms_target)
comms_target:setSharesEnergyWithDocked(true)
improvement_msg = _("situationReport-comms","We can recharge again! Come back any time to have your batteries instantly recharged.")
improvement_msg = _("situationReport-comms","We can recharge again! Come back any time to have your batteries recharged.")
comms_target.comms_data.friendlyness = math.min(comms_target.comms_data.friendlyness + random(friendliness_bonus_lo,friendliness_bonus_hi),100)
elseif improvement == "hull" then
if comms_source.instant_hull == nil then
comms_source.instant_hull = {}
end
table.insert(comms_source.instant_hull,comms_target)
comms_target:setRepairDocked(true)
improvement_msg = _("situationReport-comms","We can repair hulls again! Come back any time to have your hull instantly repaired.")
improvement_msg = _("situationReport-comms","We can repair hulls again! Come back any time to have your hull repaired.")
comms_target.comms_data.friendlyness = math.min(comms_target.comms_data.friendlyness + random(friendliness_bonus_lo,friendliness_bonus_hi),100)
elseif improvement == "restock_probes" then
if comms_source.instant_probes == nil then
comms_source.instant_probes = {}
end
table.insert(comms_source.instant_probes,comms_target)
comms_target:setRestocksScanProbes(true)
improvement_msg = _("situationReport-comms","We can restock scan probes again! Come back any time to have your scan probes instantly restocked.")
improvement_msg = _("situationReport-comms","We can restock scan probes again! Come back any time to have your scan probes restocked.")
comms_target.comms_data.friendlyness = math.min(comms_target.comms_data.friendlyness + random(friendliness_bonus_lo,friendliness_bonus_hi),100)
elseif improvement == "Nuke" then
if comms_source.nuke_discount == nil then
Expand Down
43 changes: 43 additions & 0 deletions scripts-piglit/plots/wh_exuari.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ function wh_exuari.onTeleport(wormhole, teleportee)
end
sendMessageToCampaignServer("exuari-comms", msg)
end
removeGMFunction("Exuari attack")
end
if teleportee == wh_fleetcommand.station then
if wormhole == wh_wormhole.wormhole_a then
wh_exuari.state = "idle"
addGMFunction("Exuari attack", wh_exuari.spawnSiege)
else
wh_exuari.state = "ambush"
end
Expand Down Expand Up @@ -196,6 +198,47 @@ function wh_exuari:spawnAmbush(target, strength)
end
end

function wh_exuari.spawnSiege()
local x,y = wh_wormhole.wormhole_a:getPosition()
local ambushFleet = {
fighter = {},
striker = {},
frigate = {},
artillery = {},
carrier = {},
}
table.insert(ambushFleet.carrier, tableSelectRandom(wh_exuari.shipClasses.carrier))
for i=1,12 do
table.insert(ambushFleet.fighter, tableSelectRandom(wh_exuari.shipClasses.fighter))
if i % 2 == 0 then
table.insert(ambushFleet.striker, tableSelectRandom(wh_exuari.shipClasses.striker))
end
if i % 3 == 0 then
table.insert(ambushFleet.artillery, tableSelectRandom(wh_exuari.shipClasses.artillery))
end
if i % 4 == 0 then
table.insert(ambushFleet.frigate, tableSelectRandom(wh_exuari.shipClasses.frigate))
end
end

-- spawn them!
for k,ships in pairs(ambushFleet) do
local leader, second = nil, nil
for idx,template in ipairs(ships) do
local ship = CpuShip():setTemplate(template):setPosition(x+random(-200,200),y+random(-200,200))
ship.artifacts = {}
table.insert(wh_exuari.ships, ship)
leader, second = script_formation.buildFormationIncremental(ship, idx, leader, second)
end
if leader ~= nil and wh_fleetcommand.station ~= nil and wh_fleetcommand.station:isValid() then
leader:orderAttack(wh_fleetcommand.station)
msg = string.format("Exuari %s %s reports: Death-fleet has made transit through the wormhole. Preparing to lay siege on Human Navy combat station %s. May the dead bodies of a great battle float through space.", leader:getTypeName(), leader:getCallSign(), wh_fleetcommand.station:getCallSign())
sendMessageToCampaignServer("exuari-comms", msg)
end
end
end


function wh_exuari.onDestruction(ship, instigator)
if ship.artifacts == nil or #ship.artifacts == 0 then
return
Expand Down
10 changes: 10 additions & 0 deletions scripts-piglit/plots/wh_kraylor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,27 @@ function wh_kraylor:makeFleetAggro()
fleet = tableRemoveRandom(self.fleetList)
local count = 0
local sector = nil
local first_target = nil
local first_attacker = nil
if fleet ~= nil and #fleet > 0 then
local leader = fleet[1]
if leader ~= nil and leader:isValid() then
local target = self:getTarget()
sector = leader:getSectorName()
if target ~= nil and target:isValid() and target:getFaction() ~= "Kraylor" then
leader:orderDefendTarget(target)
if first_target == nil then
first_target = target
first_attacker = leader
end
end
count = #fleet
end
end
if first_target ~= nil and first_attacker:isValid() then
msg = string.format("Kraylor %s %s: Feeble Arlenians and unworthy Humans - we will take what is rightfully ours! Surrender station %s in sector %s or prepare to be eliminated! Any resistance will be crushed!", first_attacker:getTypeName(), first_attacker:getCallSign(), first_target:getCallSign(), first_target:getSectorName())
sendMessageToCampaignServer("kraylor-comms", msg)
end
--[[
for _, sat in ipairs(scenario.spySats) do
if sat ~= nil and sat:isValid() and count > 1 then
Expand Down
6 changes: 3 additions & 3 deletions scripts-piglit/plots/wh_turns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function wh_turns:startTurn()
for id, script in pairs(self.onStart) do
script()
end
sendMessageToCampaignServer("turn", tostring(self.turn))
sendMessageToCampaignServer("turn", self.turnTime)
end

function wh_turns:startPause()
Expand All @@ -69,7 +69,7 @@ function wh_turns:startPause()
for id, script in pairs(self.onPause) do
script()
end
sendMessageToCampaignServer("pause_until", endTime)
sendMessageToCampaignServer("pause", self.pauseTime)
end

function wh_turns:startInterlude()
Expand All @@ -79,7 +79,7 @@ function wh_turns:startInterlude()
setHackingDifficulty(2)
globalMessage('', 0)
-- wait until player uses wormhole to start next turn
sendMessageToCampaignServer("interlude", "")
sendMessageToCampaignServer("interlude")
end

function wh_turns.onWormhole(wormhole, teleportee)
Expand Down

0 comments on commit acf08a7

Please sign in to comment.