mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-01-20 02:24:45 +00:00
reorganized initialization of Zones and Terminals
This commit is contained in:
parent
981acadae5
commit
2076100b50
|
|
@ -1,22 +1,27 @@
|
|||
// Copyright (c) 2017 PSForever
|
||||
package net.psforever.objects.continent
|
||||
|
||||
import akka.actor.Actor
|
||||
import akka.actor.{Actor, Props}
|
||||
import net.psforever.objects.Player
|
||||
|
||||
import scala.annotation.tailrec
|
||||
|
||||
class IntergalacticCluster(continents : List[Zone]) extends Actor {
|
||||
class IntergalacticCluster(zones : List[Zone]) extends Actor {
|
||||
private[this] val log = org.log4s.getLogger
|
||||
for(continent <- continents) {
|
||||
log.info(s"Built continent ${continent.ZoneId}")
|
||||
continent.Actor //seed context
|
||||
log.info("Starting interplanetary cluster ...")
|
||||
|
||||
override def preStart() : Unit = {
|
||||
super.preStart()
|
||||
for(zone <- zones) {
|
||||
log.info(s"Built continent ${zone.ZoneId}")
|
||||
zone.Actor = context.actorOf(Props(classOf[ZoneActor], zone), s"${zone.ZoneId}-actor")
|
||||
}
|
||||
}
|
||||
|
||||
def receive : Receive = {
|
||||
case IntergalacticCluster.GetWorld(zoneId) =>
|
||||
log.info(s"Asked to find $zoneId")
|
||||
findWorldInCluster(continents.iterator, zoneId) match {
|
||||
findWorldInCluster(zones.iterator, zoneId) match {
|
||||
case Some(continent) =>
|
||||
sender ! IntergalacticCluster.GiveWorld(zoneId, continent)
|
||||
case None =>
|
||||
|
|
@ -24,7 +29,7 @@ class IntergalacticCluster(continents : List[Zone]) extends Actor {
|
|||
}
|
||||
|
||||
case IntergalacticCluster.RequestZoneInitialization(tplayer) =>
|
||||
continents.foreach(zone => {
|
||||
zones.foreach(zone => {
|
||||
sender ! Zone.ClientInitialization(zone.ClientInitialization())
|
||||
})
|
||||
sender ! IntergalacticCluster.ClientInitializationComplete(tplayer)
|
||||
|
|
|
|||
|
|
@ -17,22 +17,29 @@ import scala.collection.mutable.ListBuffer
|
|||
|
||||
class Zone(id : String, zoneNumber : Int, map : String) {
|
||||
private var actor = ActorRef.noSender
|
||||
private var guid : NumberPoolHub = new NumberPoolHub(new LimitedNumberSource(65536))
|
||||
private var accessor : ActorRef = ActorRef.noSender
|
||||
private var startupUtilities : List[(IdentifiableEntity, Int)] = List()
|
||||
private var startupUtilities : List[(PlanetSideGameObject, Int)] = List()
|
||||
private var guid : NumberPoolHub = new NumberPoolHub(new LimitedNumberSource(65536))
|
||||
|
||||
def Actor(implicit context : ActorContext) : ActorRef = {
|
||||
def Actor : ActorRef = actor
|
||||
|
||||
def Init(implicit context : ActorContext) : Unit = {
|
||||
//TODO wrong initialization
|
||||
val pool = guid.AddPool("pool", (200 to 1000).toList)
|
||||
pool.Selector = new RandomSelector
|
||||
val poolActor = context.actorOf(Props(classOf[NumberPoolActor], pool), name = s"$ZoneId-poolActor")
|
||||
accessor = context.actorOf(Props(classOf[NumberPoolAccessorActor], guid, pool, poolActor), s"$ZoneId-accessor")
|
||||
|
||||
StartupUtilities.foreach({case ((obj, uid)) =>
|
||||
guid.register(obj, uid)
|
||||
})
|
||||
}
|
||||
|
||||
def Actor_=(zoneActor : ActorRef) : ActorRef = {
|
||||
if(actor == ActorRef.noSender) {
|
||||
actor = context.actorOf(Props(classOf[ZoneActor], this), s"$id-actor")
|
||||
|
||||
val pool = guid.AddPool("pool", (200 to 1000).toList)
|
||||
val poolActor = context.actorOf(Props(classOf[NumberPoolActor], pool), name = s"$ZoneId-poolActor")
|
||||
pool.Selector = new RandomSelector
|
||||
accessor = context.actorOf(Props(classOf[NumberPoolAccessorActor], guid, pool, poolActor), s"$ZoneId-accessor")
|
||||
|
||||
startupUtilities.foreach({case ((obj, uid)) => accessor ! Register(obj, uid, actor) })
|
||||
actor = zoneActor
|
||||
}
|
||||
actor
|
||||
Actor
|
||||
}
|
||||
|
||||
private val equipmentOnGround : ListBuffer[Equipment] = ListBuffer[Equipment]()
|
||||
|
|
@ -45,14 +52,16 @@ class Zone(id : String, zoneNumber : Int, map : String) {
|
|||
|
||||
def GUID : ActorRef = accessor
|
||||
|
||||
def GUID_=(guidSrc : NumberPoolHub) : ActorRef = {
|
||||
if(accessor == ActorRef.noSender) {
|
||||
guid = guidSrc
|
||||
def GUID(hub : NumberPoolHub) : ActorRef = {
|
||||
if(actor == ActorRef.noSender) {
|
||||
guid = hub
|
||||
}
|
||||
accessor
|
||||
Actor
|
||||
}
|
||||
|
||||
def GUID(object_guid : PlanetSideGUID) : Option[PlanetSideGameObject] = guid(object_guid.guid) match {
|
||||
def GUID(object_guid : PlanetSideGUID) : Option[PlanetSideGameObject] = GUID(object_guid.guid)
|
||||
|
||||
def GUID(object_guid : Int) : Option[PlanetSideGameObject] = guid(object_guid) match {
|
||||
case Some(obj) =>
|
||||
Some(obj.asInstanceOf[PlanetSideGameObject]) //potential casting error
|
||||
case None =>
|
||||
|
|
@ -61,10 +70,16 @@ class Zone(id : String, zoneNumber : Int, map : String) {
|
|||
|
||||
def EquipmentOnGround : ListBuffer[Equipment] = equipmentOnGround
|
||||
|
||||
def AddUtility(obj : IdentifiableEntity, id : Int) : Unit = {
|
||||
def AddUtility(obj : PlanetSideGameObject, id : Int) : Unit = {
|
||||
startupUtilities = startupUtilities :+ (obj, id)
|
||||
}
|
||||
|
||||
def StartupUtilities : List[(IdentifiableEntity, Int)] = {
|
||||
val utilities = startupUtilities
|
||||
startupUtilities = Nil
|
||||
utilities
|
||||
}
|
||||
|
||||
def ClientInitialization() : List[GamePacket] = {
|
||||
List.empty[GamePacket]
|
||||
}
|
||||
|
|
@ -75,7 +90,6 @@ class Zone(id : String, zoneNumber : Int, map : String) {
|
|||
}
|
||||
|
||||
object Zone {
|
||||
final def BlankInitFunction() : Unit = { }
|
||||
final def Nowhere : Zone = { Zone("nowhere", 0, "nowhere") } //TODO needs overrides
|
||||
|
||||
final case class DropItemOnGround(item : Equipment, pos : Vector3, orient : Vector3)
|
||||
|
|
|
|||
|
|
@ -3,24 +3,30 @@ package net.psforever.objects.continent
|
|||
|
||||
import akka.actor.Actor
|
||||
import net.psforever.objects.equipment.Equipment
|
||||
import net.psforever.objects.guid.actor.Register
|
||||
import net.psforever.packet.game.PlanetSideGUID
|
||||
|
||||
import scala.annotation.tailrec
|
||||
|
||||
class ZoneActor(continent : Zone) extends Actor {
|
||||
class ZoneActor(zone : Zone) extends Actor {
|
||||
private[this] val log = org.log4s.getLogger
|
||||
import Zone._
|
||||
|
||||
override def preStart() : Unit = {
|
||||
super.preStart()
|
||||
log.info(s"Calling ${zone.ZoneId} init ...")
|
||||
zone.Init
|
||||
}
|
||||
|
||||
def receive : Receive = {
|
||||
case DropItemOnGround(item, pos, orient) =>
|
||||
case Zone.DropItemOnGround(item, pos, orient) =>
|
||||
item.Position = pos
|
||||
item.Orientation = orient
|
||||
continent.EquipmentOnGround += item
|
||||
zone.EquipmentOnGround += item
|
||||
|
||||
case GetItemOnGround(player, item_guid) =>
|
||||
case Zone.GetItemOnGround(player, item_guid) =>
|
||||
FindItemOnGround(item_guid) match {
|
||||
case Some(item) =>
|
||||
sender ! ItemFromGround(player, item)
|
||||
sender ! Zone.ItemFromGround(player, item)
|
||||
case None =>
|
||||
log.warn(s"item on ground $item_guid was requested by $player for pickup but was not found")
|
||||
}
|
||||
|
|
@ -29,9 +35,9 @@ class ZoneActor(continent : Zone) extends Actor {
|
|||
}
|
||||
|
||||
private def FindItemOnGround(item_guid : PlanetSideGUID) : Option[Equipment] = {
|
||||
recursiveFindItemOnGround(continent.EquipmentOnGround.iterator, item_guid) match {
|
||||
recursiveFindItemOnGround(zone.EquipmentOnGround.iterator, item_guid) match {
|
||||
case Some(index) =>
|
||||
Some(continent.EquipmentOnGround.remove(index))
|
||||
Some(zone.EquipmentOnGround.remove(index))
|
||||
case None =>
|
||||
None
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import java.net.InetAddress
|
|||
import java.io.File
|
||||
import java.util.Locale
|
||||
|
||||
import akka.actor.{ActorRef, ActorSystem, Props}
|
||||
import akka.actor.{ActorContext, ActorRef, ActorSystem, Props}
|
||||
import akka.routing.RandomPool
|
||||
import ch.qos.logback.classic.LoggerContext
|
||||
import ch.qos.logback.classic.joran.JoranConfigurator
|
||||
|
|
@ -15,7 +15,6 @@ import net.psforever.crypto.CryptoInterface
|
|||
import net.psforever.objects.continent.{IntergalacticCluster, Zone}
|
||||
import net.psforever.objects.guid.TaskResolver
|
||||
import net.psforever.objects.terminals.{OrderTerminalDefinition, Terminal}
|
||||
import net.psforever.packet.game.PlanetSideGUID
|
||||
import org.slf4j
|
||||
import org.fusesource.jansi.Ansi._
|
||||
import org.fusesource.jansi.Ansi.Color._
|
||||
|
|
@ -222,11 +221,22 @@ object PsLogin {
|
|||
}
|
||||
|
||||
def createContinents() : List[Zone] = {
|
||||
val home3 = Zone("home3",13,"map13")
|
||||
val orderTerm = new OrderTerminalDefinition
|
||||
home3.AddUtility(Terminal(orderTerm), 853)
|
||||
home3.AddUtility(Terminal(orderTerm), 855)
|
||||
home3.AddUtility(Terminal(orderTerm), 860)
|
||||
val home3 = new Zone("home3",13,"map13") {
|
||||
override def Init(implicit context : ActorContext) : Unit = {
|
||||
val orderTerm = new OrderTerminalDefinition
|
||||
val obj853 = Terminal(orderTerm)
|
||||
val obj855 = Terminal(orderTerm)
|
||||
val obj860 = Terminal(orderTerm)
|
||||
AddUtility(obj853, 853)
|
||||
AddUtility(obj855, 855)
|
||||
AddUtility(obj860, 860)
|
||||
|
||||
super.Init
|
||||
obj853.Actor
|
||||
obj855.Actor
|
||||
obj860.Actor
|
||||
}
|
||||
}
|
||||
|
||||
home3 ::
|
||||
Nil
|
||||
|
|
|
|||
Loading…
Reference in a new issue