public void Reset( string type, IListener <IGameObject> scoreListener, IListener <ISoundable> soundEffectListener) { IWorld world = Character.CurrentWorld; Character.Remove(); Tuple <IGameObject, ICharacter> pair = GameObjectFactory.Instance.CreateCharacter( type, world, this, world.GetRespawnPoint(((IGameObject)Character).Boundary.Center), // TODO: remove type casting scoreListener, soundEffectListener); world.Add(pair.Item1); Character = pair.Item2; Lifes -= 1; if (Lifes < 0) { Lifes = Const.LIFES_INIT; } TimeRemain = Const.LEVEL_TIME * 1000; }
public override Error Execute() { IStronghold stronghold; if (!gameObjectLocator.TryGetObjects(strongholdId, out stronghold)) { return(Error.ObjectNotFound); } world.Add(stronghold.GateBattle); dbManager.Save(stronghold.GateBattle); //Add gate to battle var combatGroup = strongholdBattleProcedure.AddStrongholdGateToBattle(stronghold.GateBattle, stronghold); localGroupId = combatGroup.Id; stronghold.BeginUpdate(); stronghold.State = GameObjectStateFactory.BattleState(stronghold.GateBattle.BattleId); stronghold.EndUpdate(); beginTime = SystemClock.Now; endTime = SystemClock.Now.Add(formula.GetBattleDelayStartInterval()); return(Error.Ok); }
public override Error Execute() { IBarbarianTribe barbarianTribe; if (!gameObjectLocator.TryGetObjects(barbarianTribeId, out barbarianTribe)) { return(Error.ObjectNotFound); } world.Add(barbarianTribe.Battle); dbManager.Save(barbarianTribe.Battle); //Add local troop ISimpleStub simpleStub; int upkeep; byte unitLevel; formula.BarbarianTribeUpkeep(barbarianTribe.Lvl, out upkeep, out unitLevel); simpleStubGenerator.Generate(barbarianTribe.Lvl, upkeep, unitLevel, Config.barbarian_tribes_npc_randomness, (int)barbarianTribe.ObjectId + barbarianTribe.CampRemains, out simpleStub); var combatGroup = barbarianTribeBattleProcedure.AddBarbarianTribeUnitsToBattle(barbarianTribe.Battle, barbarianTribe, simpleStub.ToUnitList(FormationType.Normal)); localGroupId = combatGroup.Id; beginTime = SystemClock.Now; endTime = SystemClock.Now.Add(formula.GetBattleDelayStartInterval()); return(Error.Ok); }
public override Error Execute() { ICity city; if (!gameObjectLocator.TryGetObjects(cityId, out city)) { return(Error.ObjectNotFound); } world.Add(city.Battle); dbManager.Save(city.Battle); //Add local troop cityBattleProcedure.AddLocalUnitsToBattle(city.Battle, city); //Add reinforcement foreach ( var stub in city.Troops.Where( stub => stub != city.DefaultTroop && stub.State == TroopState.Stationed && stub.Station == city)) { stub.BeginUpdate(); stub.State = TroopState.BattleStationed; stub.EndUpdate(); battleProcedure.AddReinforcementToBattle(city.Battle, stub, FormationType.Defense); } beginTime = SystemClock.Now; endTime = SystemClock.Now.Add(formula.GetBattleDelayStartInterval()); return(Error.Ok); }
public void Move(IWorld newWorld, Point newLocation) { World.Remove(this); World = newWorld; World.Add(this); Relocate(newLocation); }
public void Request(IWorld world, Rectangle range) { if (objects != null) { foreach (IGameObject obj in objects) { world.Extend( Math.Max(world.Boundary.Left - obj.Boundary.Left, 0), Math.Max(obj.Boundary.Right - world.Boundary.Right, 0), Math.Max(world.Boundary.Top - obj.Boundary.Top, 0), Math.Max(obj.Boundary.Bottom - world.Boundary.Bottom, 0)); world.Add(obj); } objects = null; } }
private void HandleLoginProcessorResponse(Player player, LoginStatus response, IChannelHandlerContext ctx, IsaacRandomPair randomPair) { if (response != LoginStatus.StatusOk) { ctx.CloseAsync(); } else { if (player == null) { ctx.CloseAsync(); throw new InvalidOperationException("Cannot initialize player is null"); } ctx.Channel.Pipeline.Remove(nameof(LoginEncoder)); ctx.Channel.Pipeline.Remove(nameof(LoginDecoder)); var gameMessageHandlers = _gameMessageProvider.Provide(); foreach (var gameMessageHandler in gameMessageHandlers) { if (gameMessageHandler is ICipherAwareHandler) { ((ICipherAwareHandler)gameMessageHandler).CipherPair = randomPair; } if (gameMessageHandler is IPlayerAwareHandler) { ((IPlayerAwareHandler)gameMessageHandler).Player = player; } } ctx.Channel.Pipeline.AddLast(gameMessageHandlers); ctx.GetAttribute(Constants.PlayerAttributeKey).SetIfAbsent(player); player.ChannelHandlerContext = ctx; _world.Add(player); if (!_reconnecting) { _ = _playerInitializer.InitializeAsync(player); } else { player.UpdateAppearance(); } } }
public override Error Execute() { IStronghold stronghold; if (!gameObjectLocator.TryGetObjects(strongholdId, out stronghold)) { return(Error.ObjectNotFound); } world.Add(stronghold.MainBattle); dbManager.Save(stronghold.MainBattle); if (stronghold.StrongholdState == StrongholdState.Occupied) { // Add stationed to battle foreach (var stub in stronghold.Troops.StationedHere()) { stub.BeginUpdate(); stub.State = TroopState.BattleStationed; stub.EndUpdate(); battleProcedure.AddReinforcementToBattle(stronghold.MainBattle, stub, FormationType.Defense); } } else { var strongholdGroup = strongholdBattleProcedure.AddStrongholdUnitsToBattle(stronghold.MainBattle, stronghold, strongholdManager.GenerateNeutralStub(stronghold)); npcGroupId = strongholdGroup.Id; } stronghold.BeginUpdate(); stronghold.State = GameObjectStateFactory.BattleState(stronghold.MainBattle.BattleId); stronghold.EndUpdate(); beginTime = SystemClock.Now; endTime = SystemClock.Now.Add(formula.GetBattleDelayStartInterval()); return(Error.Ok); }
public void InitCharacter( string characterType, IWorld world, IListener <IGameObject> scoreListener, IListener <ISoundable> soundEffectListener) { Tuple <IGameObject, ICharacter> pair = GameObjectFactory.Instance.CreateCharacter( characterType, world, this, world.GetRespawnPoint(new Point()), scoreListener, soundEffectListener); world.Add(pair.Item1); Character = pair.Item2; Camera = GameObjectFactory.Instance.CreateCamera(); Lifes = Const.LIFES_INIT; TimeRemain = Const.LEVEL_TIME * 1000; }
protected void AddObject(string type, IWorld world, Point location) { world.Add(GameObjectFactory.Instance.CreateGameObject(type, world, location, ScoreListener, SoundListener)); }