Exemplo n.º 1
0
    public void StartTest()
    {
        var enemyUnit = new Unit(0);

        enemyUnit.SetSpecStats();
        var enemyTeam = new BattleTeam(enemyUnit);

        enemyTeam.Units[0].Controlled = false;

        var party        = MainBehaviour.Player.Parties.First();
        var myClientUnit = party.GetUnits().First();
        var myUnit       = new Unit(myClientUnit.SpecId);

        myUnit.SetSpecStats();
        var myTeam = new BattleTeam(myUnit);

        myTeam.Units[0].Controlled = true;

        Battle = new TurnBattle(Guid.NewGuid(), myTeam, enemyTeam);
        var ev = new BattleStartEvent()
        {
            Attacker = Battle.Attacker,
            BattleID = Battle.ID.ToString(),
            Defender = Battle.Defender
        };
        //EventEmitter.CallEventFromBytes(MainBehaviour.Player, Serialization.FromEvent(ev));

        var roundActions = Battle.AutoRun.PlayOneTurn();

        foreach (var action in roundActions)
        {
            //EventEmitter.CallEventFromBytes(MainBehaviour.Player, Serialization.FromEvent(new BattleActionEvent(Battle.ID.ToString(), action)));
        }
    }
Exemplo n.º 2
0
        public void TestWinner()
        {
            var battle = new TurnBattle(Guid.NewGuid(), new BattleTeam(StrongUnit), new BattleTeam(WeakUnit));
            var result = battle.AutoRun.RunAllRounds();

            Assert.AreEqual(result.Winner, result.Attacker);
        }
Exemplo n.º 3
0
        public void TestUnitsBeingUpdated()
        {
            var initialHP = StrongUnit.Stats.HP;
            var battle    = new TurnBattle(Guid.NewGuid(), new BattleTeam(StrongUnit), new BattleTeam(WeakUnit));
            var result    = battle.AutoRun.RunAllRounds();

            var finalHP = StrongUnit.Stats.HP;

            Assert.AreNotEqual(initialHP, finalHP);
        }
Exemplo n.º 4
0
        public IEnumerable <PlayerEntity> GetAllPlayers(TurnBattle battle)
        {
            PlayerEntity pl;

            foreach (var userid in new string[] { battle.Defender.OwnerID, battle.Attacker.OwnerID })
            {
                if (World.Players.GetPlayer(userid, out pl))
                {
                    yield return(pl);
                }
            }
        }
Exemplo n.º 5
0
        public void Setup()
        {
            FastUnit              = new Unit(1);
            FastUnit.Name         = "Fast Unit";
            FastUnit.Stats.Speed *= 2;

            SlowUnit              = new Unit(1);
            SlowUnit.Name         = "Slow Unit";
            SlowUnit.Stats.Speed /= 2;

            Battle = new TurnBattle(Guid.NewGuid(), new BattleTeam(FastUnit), new BattleTeam(SlowUnit));
        }
Exemplo n.º 6
0
 private static void Test2()
 {
     var battle = new TurnBattle<IActor>()
     {
         Actors = new Actor[]
         {
             new Actor("A", 10),
             new Actor("B", 12),
         },
         TurnRule = new SimpleTurnRule(),
     };
     battle.Run();
 }
Exemplo n.º 7
0
        private static void Test1()
        {
            var battle = new TurnBattle <IActorHavingSpeed>()
            {
                Actors = new ActorHavingSpeed[]
                {
                    new ActorHavingSpeed("A", 10, 2),
                    new ActorHavingSpeed("B", 12, 4),
                },
                TurnRule = new TurnRuleSpeedProvideTurn(),
            };

            battle.Run();
        }
Exemplo n.º 8
0
        private static void Test2()
        {
            var battle = new TurnBattle <IActor>()
            {
                Actors = new Actor[]
                {
                    new Actor("A", 10),
                    new Actor("B", 12),
                },
                TurnRule = new SimpleTurnRule(),
            };

            battle.Run();
        }
Exemplo n.º 9
0
        private static void Test1()
        {
            var battle = new TurnBattle<IActorHavingSpeed>()
            {
                Actors = new ActorHavingSpeed[]
                {
                    new ActorHavingSpeed("A", 10, 2),
                    new ActorHavingSpeed("B", 12, 4),
                },
                TurnRule = new TurnRuleSpeedProvideTurn(),
            };

            battle.Run();
        }
Exemplo n.º 10
0
        public void TestSerialization()
        {
            Serialization.LoadSerializers();
            var battle = new TurnBattle(Guid.NewGuid(), new BattleTeam(StrongUnit), new BattleTeam(WeakUnit));
            var result = battle.AutoRun.RunAllRounds();

            var ev = new BattleResultEvent(battle.ID.ToString(), result);

            var bytes = Serialization.FromEvent(ev);

            ev = Serialization.ToEvent <BattleResultEvent>(bytes);

            Assert.AreEqual(ev.BattleHeader.Attacker.Units.First().UnitID, result.Attacker.Units.First().UnitID);
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            ICommand[] commands = new ICommand[]
            {
                new HealCommand(),
                new DamageCommand(),
            };

            var battle = new TurnBattle<IActor>()
            {
                Actors = new IActor[]
                {
                    new CommandActor("A", 10, commands),
                    new Actor("B", 15),
                },
                TurnRule = new SimpleTurnRule(),
            };
            battle.Run();
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            ICommand[] commands = new ICommand[]
            {
                new HealCommand(),
                new DamageCommand(),
            };

            var battle = new TurnBattle <IActor>()
            {
                Actors = new IActor[]
                {
                    new CommandActor("A", 10, commands),
                    new Actor("B", 15),
                },
                TurnRule = new SimpleTurnRule(),
            };

            battle.Run();
        }
Exemplo n.º 13
0
        public void OnBattleResult(BattleResultEvent ev)
        {
            TurnBattle battle = null;

            if (!_battles.TryGetValue(ev.BattleHeader.BattleID, out battle))
            {
                ev.Sender.Send(new MessagePopupEvent(PopupType.BAD_INPUT, "Invalid battle"));
                return;
            }
            foreach (var pl in GetOnlinePlayers(battle))
            {
                var battlingParty = pl.Parties.Where(p => p != null && p.BattleID == ev.BattleHeader.BattleID).FirstOrDefault();
                if (battlingParty == null)
                {
                    throw new Exception($"Player {pl} in {this} without a party assigned");
                }
                pl.Battles.Add(ev);
            }
            _battles.Remove(ev.BattleHeader.BattleID);
        }
Exemplo n.º 14
0
        public void OnBattleStart(BattleStartEvent ev)
        {
            Console.WriteLine($"Received {ev.Attacker} vs {ev.Defender}");

            // register battle
            var battle = new TurnBattle(Guid.Parse(ev.BattleID), ev.Attacker, ev.Defender);

            battle.StartEvent = ev;
            _battles[battle.ID.ToString()] = battle;
            foreach (var onlinePlayer in GetOnlinePlayers(battle))
            {
                onlinePlayer.Send(ev);
            }

            // run battle
            var result      = battle.AutoRun.RunAllRounds();
            var resultEvent = new BattleResultEvent(battle.ID.ToString(), result);

            // handle battle finish
            foreach (var pl in GetAllPlayers(battle))
            {
                if (pl.Online())
                {
                    pl.Send(resultEvent);
                }
                pl.Battles.Add(resultEvent);
                var battlingParty = pl.Parties.Where(p => p != null && p.BattleID == resultEvent.BattleHeader.BattleID).FirstOrDefault();
                if (battlingParty != null)
                {
                    battlingParty.BattleID = null;
                }
                else
                {
                    Log.Error($"Party {battlingParty} was not part of battle {battle}");
                }
            }
        }
Exemplo n.º 15
0
 public AttackAction(TurnBattle battle, BattleUnit atk, BattleUnit def) : base(battle, atk)
 {
     this.Defender = def;
 }
Exemplo n.º 16
0
 public MoveAction(TurnBattle battle, BattleUnit atk, int tileX, int tileY) : base(battle, atk)
 {
     TileX = tileX;
     TileY = tileY;
 }