mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-02-13 03:33:37 +00:00
Added functionality to allow zone specific property override config files
This commit is contained in:
parent
d6397d54a1
commit
69e63827fa
7 changed files with 198 additions and 308 deletions
|
|
@ -75,6 +75,9 @@ class InterstellarCluster(zones : List[Zone]) extends Actor {
|
|||
}
|
||||
sender ! InterstellarCluster.PlayerList(players)
|
||||
|
||||
case InterstellarCluster.GetZoneIds() =>
|
||||
sender ! InterstellarCluster.ZoneIds(zones.map(_.Number))
|
||||
|
||||
case msg @ Zone.Lattice.RequestSpecificSpawnPoint(zone_number, _, _, _) =>
|
||||
recursiveFindWorldInCluster(zones.iterator, _.Number == zone_number) match {
|
||||
case Some(zone) =>
|
||||
|
|
@ -219,4 +222,7 @@ object InterstellarCluster {
|
|||
* @param zone_num the zone number to request building map updates for
|
||||
*/
|
||||
final case class ZoneMapUpdate(zone_num : Int)
|
||||
|
||||
final case class GetZoneIds()
|
||||
final case class ZoneIds(zoneIds : List[Int])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -187,6 +187,7 @@ object ObjectClass {
|
|||
final val katana = 421
|
||||
final val lancer = 425
|
||||
final val lasher = 429
|
||||
final val lasher_projectile_ap = 431
|
||||
final val liberator_25mm_cannon = 433
|
||||
final val liberator_bomb_bay = 435
|
||||
final val liberator_weapon_system = 440
|
||||
|
|
@ -398,6 +399,26 @@ object ObjectClass {
|
|||
final val targeting_laser_dispenser = 851
|
||||
final val teleportpad_terminal = 853
|
||||
|
||||
|
||||
final val objectClassMap = scala.collection.mutable.Map[String, Int]()
|
||||
|
||||
def ByName(name : String) : Int = {
|
||||
// This whole thing is a dirty "temporary" hack so I don't have to make a huge map out of the above object vars by hand
|
||||
// Forgive me.
|
||||
if(objectClassMap.size == 0) {
|
||||
val objectClassMethods = ObjectClass.getClass.getDeclaredMethods
|
||||
objectClassMethods.foreach(x => {
|
||||
if(x.getReturnType.getName == "int" && x.getParameterTypes.isEmpty) { // ints only & Ignore functions with parameters
|
||||
val objectName = x.getName
|
||||
val value = ObjectClass.getClass.getMethod(objectName).invoke(ObjectClass)
|
||||
objectClassMap.put(objectName, value.asInstanceOf[Int])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
objectClassMap(name.toLowerCase())
|
||||
}
|
||||
|
||||
//TODO refactor the following functions into another object later
|
||||
/**
|
||||
* Given an object class, retrieve the `Codec` used to parse and translate the constructor data for that type.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,131 @@
|
|||
package services.properties
|
||||
|
||||
|
||||
import akka.actor.{Actor, ActorRef, Stash}
|
||||
import net.psforever.objects.zones.InterstellarCluster
|
||||
import net.psforever.packet.game.{GamePropertyTarget, PropertyOverrideMessage}
|
||||
import net.psforever.packet.game.PropertyOverrideMessage.GamePropertyScope
|
||||
import net.psforever.packet.game.objectcreate.ObjectClass
|
||||
import services.ServiceManager
|
||||
import services.ServiceManager.Lookup
|
||||
|
||||
import scala.collection.mutable.ListBuffer
|
||||
|
||||
class PropertyOverrideManager extends Actor with Stash {
|
||||
private[this] val log = org.log4s.getLogger("PropertyOverrideManager")
|
||||
|
||||
private var overrides : Map[Int, Map[String, List[(String, String)]]] = Map()
|
||||
private var gamePropertyScopes : List[PropertyOverrideMessage.GamePropertyScope] = List()
|
||||
private var interstellarCluster : ActorRef = Actor.noSender
|
||||
private var zoneIds : List[Int] = List()
|
||||
|
||||
override def preStart = {
|
||||
log.info(s"Starting PropertyOverrideManager")
|
||||
ServiceManager.serviceManager ! Lookup("cluster")
|
||||
}
|
||||
|
||||
override def receive = ServiceLookup
|
||||
|
||||
def ServiceLookup : Receive = {
|
||||
case ServiceManager.LookupResult("cluster", endpoint) =>
|
||||
interstellarCluster = endpoint
|
||||
|
||||
if (interstellarCluster != ActorRef.noSender) {
|
||||
interstellarCluster ! InterstellarCluster.GetZoneIds()
|
||||
}
|
||||
|
||||
case InterstellarCluster.ZoneIds(zoneIds) =>
|
||||
this.zoneIds = zoneIds
|
||||
|
||||
unstashAll()
|
||||
LoadOverridesFromFile(zoneId = 0) // Global overrides
|
||||
for(zoneId <- zoneIds) {
|
||||
LoadOverridesFromFile(zoneId)
|
||||
}
|
||||
|
||||
ProcessGamePropertyScopes()
|
||||
|
||||
context.become(ReceiveCommand)
|
||||
|
||||
case _ => stash()
|
||||
}
|
||||
|
||||
def ReceiveCommand: Receive = {
|
||||
case PropertyOverrideManager.GetOverridesMessage => {
|
||||
sender ! gamePropertyScopes
|
||||
}
|
||||
case _ => ;
|
||||
}
|
||||
|
||||
private def LoadOverridesFromFile(zoneId : Int): Unit = {
|
||||
val zoneOverrides = LoadFile(s"game_objects${zoneId}.adb.lst")
|
||||
|
||||
if(zoneOverrides == null) {
|
||||
log.info(s"No overrides found for zone ${zoneId} using filename game_objects${zoneId}.adb.lst")
|
||||
return
|
||||
}
|
||||
|
||||
val grouped = zoneOverrides.groupBy(_._1).view.mapValues(_.map(x => (x._2, x._3)).toList).toMap
|
||||
|
||||
log.info(s"Loaded property overrides for zone $zoneId: ${grouped.toString}")
|
||||
overrides += (zoneId -> grouped)
|
||||
}
|
||||
|
||||
private def ProcessGamePropertyScopes(): Unit = {
|
||||
val scopesBuffer : ListBuffer[GamePropertyScope] = ListBuffer()
|
||||
|
||||
for(over <- overrides) {
|
||||
val zoneId = over._1
|
||||
val overrideMap = over._2
|
||||
|
||||
val gamePropertyTargets : ListBuffer[PropertyOverrideMessage.GamePropertyTarget] = ListBuffer()
|
||||
|
||||
for(propOverride <- overrideMap) {
|
||||
val objectId = ObjectClass.ByName(propOverride._1)
|
||||
val props = GamePropertyTarget(objectId,propOverride._2)
|
||||
gamePropertyTargets += props
|
||||
}
|
||||
|
||||
val scope = GamePropertyScope(zoneId, gamePropertyTargets.toList)
|
||||
|
||||
scopesBuffer += scope
|
||||
}
|
||||
|
||||
gamePropertyScopes = scopesBuffer.toList
|
||||
}
|
||||
|
||||
def LoadFile(path : String): ListBuffer[(String, String, String)] = {
|
||||
val stream = getClass.getClassLoader.getResourceAsStream(path)
|
||||
if(stream == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
val content = scala.io.Source.fromInputStream(stream).getLines().filter(x => x.startsWith("add_property"))
|
||||
var data : ListBuffer[(String, String, String)] = ListBuffer()
|
||||
|
||||
for(line <- content) {
|
||||
val splitLine = line.split(" ")
|
||||
if(splitLine.length >= 3) {
|
||||
val objectName = splitLine(1)
|
||||
val property = splitLine(2)
|
||||
|
||||
var propertyValue = ""
|
||||
for(i <- 3 to splitLine.length - 1) {
|
||||
propertyValue += splitLine(i) + " "
|
||||
}
|
||||
propertyValue = propertyValue.trim
|
||||
|
||||
data += ((objectName, property, propertyValue))
|
||||
}
|
||||
}
|
||||
|
||||
stream.close()
|
||||
|
||||
data
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
object PropertyOverrideManager {
|
||||
final case class GetOverridesMessage()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue