private void Initialize(IPlayerLocator player_locator, ISceneManager scene_manager, INetworkEngineConnector network_connector)
    {
        scene_manager.OnRoomLoaded
        .Subscribe(_ =>
        {
            SubscribeEvents();
        })
        .AddTo(this);

        network_connector.OnJoinedRoomAsObservable
        .Subscribe(_ =>
        {
            m_AvatarSpawner = new PlayerAvatarSpawner(m_RuntimeModelLoader, player_locator);
            m_AvatarSpawner.Spawn(AvatarPath, m_SpawnPosTag);
        })
        .AddTo(this);

        network_connector.OnLeftRoomAsObservable
        .Subscribe(_ =>
        {
            UnsubscribeEvents();
            DestroyAvatar();
        })
        .AddTo(this);


        m_RuntimeModelLoader.OnLoadModelCompleted
        .Subscribe(model =>
        {
            m_AvatarModel = model;
            m_LoadModelCompleted.OnNext(model);
        })
        .AddTo(this);
    }
Example #2
0
        public Ship(ShipModelType s, LocatorService ls)
        {
            _model = s;

            StatBonuses = new ShipBonusHandler();

            Debuffs = new DebuffHandler();

            switch (ShipStats.ShieldType)
            {
            case ShieldTypes.QuickRegen:
                Shields = new QuickRegenShieldHandler(ShipStats, StatBonuses, Debuffs);
                break;

            case ShieldTypes.SlowRegen:
                Shields = new SlowRegenShieldHandler(ShipStats, StatBonuses, Debuffs);
                break;

            case ShieldTypes.NoRegen:
                Shields = new NoRegenShieldHandler(ShipStats, StatBonuses, Debuffs);
                break;
            }

            RecalculateModuleBonuses();

            Cargo = new CargoHandler_ReadOnlyVM <CargoHandlerModel>(s.Cargo);


            _playerLocator = ls.PlayerLocator;
            _areaLocator   = ls.AreaLocator;
            _teamLocator   = ls.TeamLocator;
        }
Example #3
0
 public GlobalTeamManager(LocalIDManager IDSupplier, ConnectionManager cm, RedisServer rs, IPlayerLocator pl, IDatabaseManager dbm)
 {
     _teamIDSupplier    = IDSupplier;
     _connectionManager = cm;
     _redisServer       = rs;
     _playerLocator     = pl;
     _databaseManager   = dbm;
 }
Example #4
0
 protected Area(ModelType a, LocatorService ls)
 {
     _model          = a;
     _playerLocator  = ls.PlayerLocator;
     _areaLocator    = ls.AreaLocator;
     _shipLocator    = ls.ShipLocator;
     _structures     = new Dictionary <int, IStructure>();
     _lastUpdateTime = TimeKeeper.MsSinceInitialization;
 }
Example #5
0
        public Ship(ShipStats stats, LocatorService ls)
        {
            _model   = new ShipModelType();
            PosX     = 0;
            PosY     = 0;
            Rotation = 0;
            VelY     = 0;
            VelX     = 0;
            _weapons = new List <Weapon>();
            _model.MissileLauncherSlot = 0;
            _weapons.Add(new MissileLauncher(ProjectileTypes.AmbassadorMissile));



            TimeOfLastCollision = 0;
            TimeOfLastDamage    = 0;
            DoCombatUpdates     = false;

            HealthUpdatePeriod = 500;

            _model.PlayerID     = null;
            _simulatingPlayerID = null;
            IsNPC = false;


            _playerLocator = ls.PlayerLocator;
            _areaLocator   = ls.AreaLocator;
            _teamLocator   = ls.TeamLocator;


            _model.Modules = new List <Module>();
            StatBonuses    = new ShipBonusHandler();

            Debuffs = new DebuffHandler();

            switch (stats.ShieldType)
            {
            case ShieldTypes.QuickRegen:
                Shields = new QuickRegenShieldHandler(stats, StatBonuses, Debuffs);
                break;

            case ShieldTypes.SlowRegen:
                Shields = new SlowRegenShieldHandler(stats, StatBonuses, Debuffs);
                break;

            case ShieldTypes.NoRegen:
                Shields = new NoRegenShieldHandler(stats, StatBonuses, Debuffs);
                break;
            }
            ShipStats = stats;


            _model.Cargo = new CargoHandlerModel();
            Cargo        = new CargoHandler_ReadOnlyVM <CargoHandlerModel>(_model.Cargo);
            SetHealthAndShields(stats);
        }
 public ServerGameStateManager(IPlayerLocator pl, IAreaLocator al, ITeamLocator tl, MessageManager mm, WarpManager wm, ChatManager cm, ITradeTerminator tt)
 {
     _playerLocator = pl;
     _areaLocator = al;
     _teamLocator = tl;
     _messageManager = mm;
     _warpManager = wm;
     _chatManager = cm;
     _tradeTerminator = tt;
 }
 private void Initialize(ISceneManager scene_manager, IPlayerLocator player_locator)
 {
     scene_manager.OnLobbyLoaded
     .Subscribe(_ =>
     {
         player_locator.Player.transform.position = Vector3.zero;
         player_locator.Player.transform.rotation = Quaternion.identity;
     })
     .AddTo(this);
 }
Example #8
0
        public DefensiveMine(float xPos, float yPos, int galaxyID, int ownerID, int currentAreaID, IPlayerLocator playerLocator) : base(xPos, yPos, galaxyID, ownerID, currentAreaID)
        {
            _model = new DefensiveMineModel(base._model);
            _model.StructureType = StructureTypes.DefensiveMine;
            Debuffs = new DebuffHandler();

            Id = galaxyID;

            _playerLocator = playerLocator;
            _model.Weapon  = new MineWeapon();
        }
Example #9
0
 public KillManager(CargoSynchronizer cargoSynchronizer, IPlayerLocator pl, IAreaLocator al, MessageManager mm, ConnectionManager cm, WarpManager wm, ChatManager chatManager, ITradeTerminator tradeTerminator)
 {
     _cargoSynchronizer = cargoSynchronizer;
     _messageManager    = mm;
     _connectionManager = cm;
     _warpManager       = wm;
     _areaLocator       = al;
     _playerLocator     = pl;
     _chatManager       = chatManager;
     _tradeTerminator   = tradeTerminator;
 }
Example #10
0
        public Turret(int galaxyID, float xPos, float yPos, int ownerID, int currentAreaID, TurretTypes turretType, IPlayerLocator pl)
            : base(xPos, yPos, galaxyID, ownerID, currentAreaID)
        {
            _model = new TurretModel(base._model, turretType);
            _model.StructureType = StructureTypes.LaserTurret;
            Debuffs = new DebuffHandler();

            Id = galaxyID;

            _playerLocator = pl;
            _model.Weapon  = new AltLaser();
        }
Example #11
0
        protected Area(int ID, LocatorService ls)
        {
            _model = new ModelType();
            Id     = ID;

            _playerLocator            = ls.PlayerLocator;
            _areaLocator              = ls.AreaLocator;
            _shipLocator              = ls.ShipLocator;
            _structures               = new Dictionary <int, IStructure>();
            _model.FloatySpaceObjects = new Dictionary <int, IFloatyAreaObject>();
            _lastUpdateTime           = TimeKeeper.MsSinceInitialization;
        }
Example #12
0
        // Need to find a better place for this...
        public static IStructure InstantiateStructure(IStructureModel sm, IPlayerLocator pl, IGalaxyRegistrationManager gm)
        {
            IStructure s;

            switch (sm.StructureType)
            {
            case (StructureTypes.LaserTurret):
                s = new Turret((TurretModel)sm, pl);
                break;

            case (StructureTypes.Biodome):
                s = new Biodome((BiodomeModel)sm);
                break;

            case (StructureTypes.PowerPlant):
                s = new PowerPlant((PowerPlantModel)sm);
                break;

            case (StructureTypes.Silo):
                s = new Silo((SiloModel)sm);
                break;

            case (StructureTypes.CommandCenter):
                return(new CommandCenter((CommandCenterModel)sm));

            case (StructureTypes.Factory):
                s = new Factory((FactoryModel)sm);
                break;

            case StructureTypes.Refinery:
                s = new Refinery((RefineryModel)sm);
                break;

            case StructureTypes.Mine:
                s = new MineStructure((MineModel)sm);
                break;

            case StructureTypes.DefensiveMine:
                s = new DefensiveMine((DefensiveMineModel)sm, pl);
                break;

            case StructureTypes.ConstructionBuilding:
                s = new ConstructionBuilding((ConstructionBuildingModel)sm);
                break;

            default:
                throw new Exception("CreateStructure not implemented for structure type " + sm.StructureType.ToString());
            }
            gm.RegisterObject(s);


            return(s);
        }
Example #13
0
        public EconomyManager(LocalIDManager transactionIDManager, IPlayerLocator pl, IAreaLocator al, CargoSynchronizer cs, ShipManager sm, IDatabaseManager databaseManager, ISlaveIDProvider slaveIDProvider)
        {
            _shipManager       = sm;
            _playerLocator     = pl;
            _areaLocator       = al;
            _cargoSynchronizer = cs;

            _tradeIDManager  = transactionIDManager;
            _databaseManager = databaseManager;
            _slaveIDProvider = slaveIDProvider;

            _shipShipTrades       = new ConcurrentDictionary <int, ShipShipTrade>();
            _shipIDToTradeID      = new ConcurrentDictionary <int, int>();
            _pendingTradeRequests = new ConcurrentDictionary <int, TradeRequest>();
            _tradingPlayerIDs     = new HashSet <int>();
        }
Example #14
0
        /// <summary>
        /// Returns null if area is not found. Will probably be depreciated soon, because of excessive querying.
        /// Note that this method does not load nested references if they are stored as Ids (e.g. planets in systems, which are stored only by IDs: PSystem.PlanetIDs)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Area GetArea(int id, IPlayerLocator pl, IAreaLocator al, IShipLocator sl, IMessageManager mm, IGalaxyRegistrationManager rm, ITeamLocator tl)
        {
            //Apparently, include is retardedly slow, so we have to use a manual workaround.
            //DBArea a = _galacticObjectContext.Areas.Include(e=>e.Warpholes).Include(se=>se.Structures).First(ee=>ee.Id == id);
            Area retArea;

            using (GalacticObjectContext context = new GalacticObjectContext())
            {
                context.SetLogger(Logger);

                if (context.Systems.Any(e => e.Id == id))
                {
                    retArea = GetSystem(context, id, pl, al, sl, mm);
                }
                else if (context.Moons.Any(e => e.Id == id))
                {
                    retArea = GetMoon(context, id, pl, al, sl, mm);
                }
                else if (context.Planets.Any(e => e.Id == id))
                {
                    retArea = GetPlanet(context, id, pl, al, sl, mm, rm, tl);
                }
                else if (context.Ports.Any(e => e.Id == id))
                {
                    retArea = GetPort(context, id, pl, al, sl, mm);
                }
                else if (context.Colonies.Any(e => e.Id == id))
                {
                    retArea = GetColony(context, id, pl, al, sl, mm);
                }
                else
                {
                    throw new Exception("Error: Area not found. Has deserialization been imlemented for this type?");
                }


                List <IHasGalaxyID> l = new List <IHasGalaxyID>();
                retArea.GetRegisterableNestedObjects(l);
                foreach (IHasGalaxyID obj in l)
                {
                    rm.RegisterObject(obj);
                }
            }
            return(retArea);
        }
Example #15
0
        /// <summary>
        /// Does not load or register nested objects within systems (e.g. planets)
        /// </summary>
        /// <param name="pl"></param>
        /// <param name="al"></param>
        /// <param name="sl"></param>
        /// <param name="mm"></param>
        /// <returns></returns>
        public IEnumerable <PSystem> GetAllSystems(IPlayerLocator pl, IAreaLocator al, IShipLocator sl, IMessageManager mm)
        {
            IEnumerable <DBArea> allAreas = _galacticObjectContext.Systems;

            List <PSystem> acc = new List <PSystem>();

            foreach (DBArea a in allAreas)
            {
                switch (a.Type)
                {
                case AreaTypes.System:
                    acc.Add(new PSystem((DBPSystem)a, pl, al, sl, mm));
                    break;
                }
            }

            return(acc);
        }
Example #16
0
        public IEnumerable <Ship> GetAllShips(IPlayerLocator pl, IAreaLocator al, ITeamLocator tl)
        {
            IEnumerable <DBShip> allShips = _galacticObjectContext.Ships;

            List <Ship> acc = new List <Ship>();

            foreach (DBShip s in allShips)
            {
                switch (s.PilotType)
                {
                case PilotTypes.Player:
                    acc.Add(new PlayerShip((DBPlayerShip)s, pl, al, tl));
                    break;

                default:
                    throw new Exception("Error: Deserialization not implemented for ship of PilotType " + s.PilotType);
                }
            }

            return(acc);
        }
Example #17
0
        /// <summary>
        /// Returns null if ship is not found
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Ship GetShip(int id, IPlayerLocator pl, IAreaLocator al, ITeamLocator tl)
        {
            //Include is important, requires EF to load specified related entities, which otherwise aren't loaded with the DBShip, because of performance (fewer joins). The alternative is lazy loading with virtual, but this is way cooler bro.
            //Probably should use virtuals in the future, though.
            DBShip s = _galacticObjectContext.Ships.Include(e => e.PrimaryWeapon).Include(x => x.SecondaryWeapon).Include(y => y.MissileLauncher).First(ls => ls.Id == id);

            if (s == null)
            {
                return(null);
            }
            else
            {
                switch (s.PilotType)
                {
                case PilotTypes.Player:
                    return(new PlayerShip((DBPlayerShip)s, pl, al, tl));

                default:
                    throw new Exception("Error: Deserialization not implemented for ship of PilotType " + s.PilotType);
                }
            }
        }
Example #18
0
 public LocatorService(IGalaxyRegistrationManager grm,
                       IPlayerLocator pl,
                       IAreaLocator al,
                       IShipLocator sl,
                       IAccountLocator acl,
                       ITeamLocator tl,
                       ITeamManager tm,
                       IMessageManager mm,
                       IObjectLocator <IStructure> structureManager,
                       ISlaveIDProvider slaveIDProvider)
 {
     PlayerLocator       = pl;
     ShipLocator         = sl;
     AccountLocator      = acl;
     TeamLocator         = tl;
     TeamManager         = tm;
     AreaLocator         = al;
     MessageManager      = mm;
     RegistrationManager = grm;
     StructureManager    = structureManager;
     SlaveIDProvider     = slaveIDProvider;
 }
Example #19
0
        public Planet GetPlanet(GalacticObjectContext context, int id, IPlayerLocator pl, IAreaLocator al, IShipLocator sl, IMessageManager mm, IGalaxyRegistrationManager rm, ITeamLocator tl)
        {
            var a = context.Planets.Include(e0 => e0.Warpholes).Include(e1 => e1.Structures).Include(e2 => e2.Colony).First(e3 => e3.Id == id);

            if (a != null)
            {
                Planet retArea = new Planet(a, pl, al, sl, mm, tl);
                if (a.Colony != null)
                {
                    Colony col = new Colony(a.Colony, pl, al, sl, mm);
                    rm.RegisterObject(col);

                    foreach (var s in retArea.GetStructures())
                    {
                        col.RegisterStructure(s.Value);
                    }
                }
            }


            return(a == null ? null : new Planet(a, pl, al, sl, mm, tl));
        }
Example #20
0
        /// <summary>
        /// For structures which originate as StatefulCargo, as they already have a GalaxyID
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public static IStructure CreateStructure(StatefulCargo c, float xPos, float yPos, Player owner, CommandCenter commandCenter, int currentAreaID, IPlayerLocator pl)
        {
            IStructure s;

            switch (c.Type)
            {
            case (StatefulCargoTypes.LaserTurret):
                s = new Turret(_localIDManager.PopFreeID(), xPos, yPos, owner, commandCenter, currentAreaID, pl);
                break;

            default:
                throw new Exception("CreateStructure not implemented for structure type " + c.Type.ToString());
            }
            _galaxyRegistrationManager.RegisterObject(s);

            return(s);
        }
Example #21
0
        public Colony GetColony(GalacticObjectContext context, int id, IPlayerLocator pl, IAreaLocator al, IShipLocator sl, IMessageManager mm)
        {
            var a = context.Colonies.First(e3 => e3.Id == id);

            return(a == null ? null : new Colony(a, pl, al, sl, mm));
        }
Example #22
0
 public void Test(IDatabaseManager dbm, IPlayerLocator pl, IAreaLocator al, ITeamLocator tl, IShipLocator sl, IMessageManager mm, IAccountLocator acl, ITeamManager tm)
 {
 }
Example #23
0
 static async Task InstantiateStructures(IEnumerable <IArea> loadedAreas, Dictionary <int, IStructureModel> loadedStructureModels, IGalaxyRegistrationManager rm, IPlayerLocator pl)
 {
     foreach (IArea a in loadedAreas)
     {
         var structureIDs = a.GetStructureIDs();
         foreach (int id in structureIDs)
         {
             IStructure s = StructureHelper.InstantiateStructure(loadedStructureModels[id], pl, rm);
             a.AddStructure(s);
         }
     }
 }
Example #24
0
        /// <summary>
        /// Loads the structures associated with the given object
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static async Task <List <IStructure> > LoadStructures(IHasStructures loadMine, IDatabaseManager dbm, IGalaxyRegistrationManager rm, IPlayerLocator pl)
        {
            var loadedStructureModels = await dbm.GetStructuresAsync(loadMine.GetStructureIDs());

            List <IStructure> loadedStructures = new List <IStructure>();

            foreach (var ls in loadedStructureModels)
            {
                IStructure s = StructureHelper.InstantiateStructure(ls, pl, rm);
                loadMine.AddStructure(s);
                loadedStructures.Add(s);
            }

            return(loadedStructures);
        }
Example #25
0
        /// <summary>
        /// For structures which originate as StatefulCargo, as they already have a GalaxyID
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public static IStructure CreateStructure(StatefulCargo c, float xPos, float yPos, Player owner, CommandCenter commandCenter, int currentAreaID, IPlayerLocator pl)
        {
            IStructure s;

            switch (c.CargoType)
            {
            case (StatefulCargoTypes.LaserTurret):
            {
                TurretTypes t = owner.GetArea().AreaType == AreaTypes.Planet ? TurretTypes.Planet : TurretTypes.Space;
                s = new Turret(c.Id, xPos, yPos, owner.Id, currentAreaID, t, pl);
                break;
            }

            case (StatefulCargoTypes.DefensiveMine):
            {
                s = new DefensiveMine(xPos, yPos, c.Id, owner.Id, currentAreaID, pl);
                break;
            }

            default:
                throw new Exception("CreateStructure not implemented for structure type " + c.CargoType.ToString());
            }
            _galaxyRegistrationManager.RegisterObject(s);

            return(s);
        }
Example #26
0
 public DefensiveMine(DefensiveMineModel model, IPlayerLocator playerLocator) : base(model)
 {
     _model         = model;
     _playerLocator = playerLocator;
 }
Example #27
0
        /// <summary>
        /// Creates a structure
        /// </summary>
        /// <param name="type"></param>
        /// <param name="xPos"></param>
        /// <param name="yPos"></param>
        /// <param name="owner"></param>
        /// <param name="commandCenter"></param>
        /// <param name="currentAreaID"></param>
        /// <param name="pl"></param>
        /// <param name="writeToDB">If true, must specify dbm</param>
        /// <param name="dbm">must be specified if writeToDB is true</param>
        /// <returns></returns>
        public static IStructure CreateStructure(StructureTypes type, float xPos, float yPos, Player owner, CommandCenter commandCenter, int currentAreaID, IPlayerLocator pl, bool writeToDB = false, IDatabaseManager dbm = null)
        {
            IStructure s;

            switch (type)
            {
            case (StructureTypes.LaserTurret):
                TurretTypes t = owner.GetArea().AreaType == AreaTypes.Planet ? TurretTypes.Planet : TurretTypes.Space;
                s = new Turret(_localIDManager.PopFreeID(), xPos, yPos, owner.Id, currentAreaID, t, pl);

                break;

            case (StructureTypes.Biodome):
                return(CreateBiodome(xPos, yPos, owner, currentAreaID));

            case (StructureTypes.PowerPlant):
                s = new PowerPlant(xPos, yPos, _localIDManager.PopFreeID(), owner.Id, currentAreaID);
                break;

            case (StructureTypes.Silo):
                s = new Silo(xPos, yPos, _localIDManager.PopFreeID(), owner.Id, currentAreaID);
                break;

            case (StructureTypes.CommandCenter):
                return(CreateCommandCenter(xPos, yPos, owner, currentAreaID));

            case (StructureTypes.Factory):
                s = new Factory(xPos, yPos, _localIDManager.PopFreeID(), owner.Id, currentAreaID);
                break;

            default:
                throw new Exception("CreateStructure not implemented for structure type " + type.ToString());
            }
            _galaxyRegistrationManager.RegisterObject(s);

            if (writeToDB)
            {
                if (dbm == null)
                {
                    throw new Exception("Error: must specify IDatabaseManager dbm if writeToDB is true.");
                }
                else
                {
                    dbm.SaveAsync(s);
                }
            }

            return(s);
        }
Example #28
0
 public Turret(TurretModel tm, IPlayerLocator pl) : base(tm)
 {
     _playerLocator = pl;
     Debuffs        = new DebuffHandler();
 }
 public PlayerAvatarSpawner(IRuntimeModelLoader model_loader, IPlayerLocator player_locator)
 {
     m_ModelLoader   = model_loader;
     m_PlayerLocator = player_locator;
 }
Example #30
0
        /// <summary>
        /// Creates a structure
        /// </summary>
        /// <param name="type"></param>
        /// <param name="health"></param>
        /// <param name="xPos"></param>
        /// <param name="yPos"></param>
        /// <param name="owner"></param>
        /// <param name="commandCenter"></param>
        /// <returns></returns>
        public static IStructure CreateStructure(StructureTypes type, float xPos, float yPos, Player owner, CommandCenter commandCenter, int currentAreaID, IPlayerLocator pl)
        {
            IStructure s;

            switch (type)
            {
            case (StructureTypes.LaserTurret):
                s = new Turret(_localIDManager.PopFreeID(), xPos, yPos, owner, commandCenter, currentAreaID, pl);
                break;

            case (StructureTypes.Biodome):
                s = new Biodome(xPos, yPos, _localIDManager.PopFreeID(), owner, currentAreaID);
                break;

            case (StructureTypes.PowerPlant):
                s = new PowerPlant(xPos, yPos, _localIDManager.PopFreeID(), owner, currentAreaID);
                break;

            case (StructureTypes.Silo):
                s = new Silo(xPos, yPos, _localIDManager.PopFreeID(), owner, currentAreaID);
                break;


            default:
                throw new Exception("CreateStructure not implemented for structure type " + type.ToString());
            }
            _galaxyRegistrationManager.RegisterObject(s);

            return(s);
        }