Ejemplo n.º 1
0
        public static void CreatureUpdate(Client client, Battle battle, Creature creature)
        {
            NewEffects newEffects               = new NewEffects();
            NewEffects.Effect statsUpdateEffect = new NewEffects.Effect();

            NewEffects.Effect.Target target = new NewEffects.Effect.Target();
            target.color    = battle.color;
            target.position = creature.posY + "," + creature.posX;

            statsUpdateEffect.StatsUpdate        = new NewEffects.Effect.StatsUpdateEffect();
            statsUpdateEffect.StatsUpdate.target = target;
            statsUpdateEffect.StatsUpdate.hp     = creature.currentHp;
            statsUpdateEffect.StatsUpdate.ac     = creature.currentAc;
            statsUpdateEffect.StatsUpdate.ap     = creature.currentAp;

            newEffects.effects.Add(statsUpdateEffect);

            client.Send(newEffects);
            GetOpponentClient(battle).Send(newEffects);
        }
Ejemplo n.º 2
0
        public static void PlayCard(Client client, string jsonPacketData)
        {
            client.packetMap.Remove("PlayCard");

            PlayCard playCard = JsonConvert.DeserializeObject<PlayCard>(jsonPacketData);

            Battle battle = BattleAPI.GetBattle(client.account.username);

            if (battle.handMap.ContainsKey(playCard.card))
            {
                NewEffects newEffects = new NewEffects();

                foreach (string positionData in playCard.data.positions)
                {
                    Card card         = CardAPI.GetCard(client, playCard.card);
                    CardType cardType = CardAPI.GetCardType(card.typeId);

                    if (BattleAPI.EnoughResources(battle, cardType))
                    {
                        BattleAPI.DecreaseResource(battle, cardType.GetResourceType(), cardType.GetResourceCost());

                        string[] positionDataArray = positionData.Split(',');

                        NewEffects.Effect.Target target = new NewEffects.Effect.Target();
                        target.color    = battle.color;
                        target.position = positionDataArray[1] + "," + positionDataArray[2];

                        NewEffects.Effect cardPlayedEffect  = new NewEffects.Effect();
                        NewEffects.Effect summonUnitEffect  = new NewEffects.Effect();
                        NewEffects.Effect statsUpdateEffect = new NewEffects.Effect();

                        cardPlayedEffect.CardPlayed       = new NewEffects.Effect.CardPlayedEffect();
                        cardPlayedEffect.CardPlayed.card  = card;
                        cardPlayedEffect.CardPlayed.color = battle.color;
                        cardPlayedEffect.CardPlayed.tile1 = target;

                        newEffects.effects.Add(cardPlayedEffect);

                        if (cardType.kind == "CREATURE" || cardType.kind == "STRUCTURE")
                        {
                            Creature creature = new Creature()
                            {
                                kind      = cardType.kind,
                                posX      = Convert.ToInt16(positionDataArray[2]),
                                posY      = Convert.ToInt16(positionDataArray[1]),
                                defaultHp = cardType.hp,
                                defaultAp = cardType.ap,
                                defaultAc = cardType.ac,
                                currentHp = cardType.hp,
                                currentAp = cardType.ap,
                                currentAc = cardType.ac
                            };

                            if (cardType.ac == -1)
                            {
                                creature.canTick = false;
                            }
                            else
                            {
                                creature.canTick = true;
                            }

                            foreach (string subType in cardType.subTypes)
                            {
                                creature.subTypes.Add(subType);
                            }

                            foreach (string rule in cardType.rulesList)
                            {
                                creature.ruleList.Add(rule);
                            }

                            summonUnitEffect.SummonUnit        = new NewEffects.Effect.SummonUnitEffect();
                            summonUnitEffect.SummonUnit.card   = card;
                            summonUnitEffect.SummonUnit.target = target;

                            newEffects.effects.Add(summonUnitEffect);

                            RuleHandler.HandleCreatureStructureSummon(client, ref creature, battle);

                            statsUpdateEffect.StatsUpdate        = new NewEffects.Effect.StatsUpdateEffect();
                            statsUpdateEffect.StatsUpdate.target = target;
                            statsUpdateEffect.StatsUpdate.hp     = creature.currentHp;
                            statsUpdateEffect.StatsUpdate.ap     = creature.currentAp;
                            statsUpdateEffect.StatsUpdate.ac     = creature.currentAc;

                            newEffects.effects.Add(statsUpdateEffect);

                            battle.board[creature.posX, creature.posY] = creature;
                        }
                        if (cardType.kind == "ENCHANTMENT" || cardType.kind == "SPELL")
                        {
                            //RuleHandler.HandleEnchantmentSpellPlay(battle);
                        }

                        battle.handMap.Remove(playCard.card);

                        BattleAPI.ResourcesUpdate(client, battle);
                        BattleAPI.UpdateHand(client, battle);
                    }
                    else
                    {
                        Console.WriteLine("{0} tried to play card {1} but they don't have enough resources!", client.account.username, card.id);
                    }
                }

                client.Send(newEffects);
                BattleAPI.GetOpponentClient(battle).Send(newEffects);
            }
            else
            {
                Console.WriteLine("{0} tried to play card {1} which they don't have in hand!", client.account.username, playCard.card);
            }
        }
Ejemplo n.º 3
0
        public static void HandleCreatureStructureAttack(Client client, ref Creature creature, Battle battle)
        {
            bool attackingCreatureAlive = true;

            Battle opponentBattle = BattleAPI.GetOpponentBattle(battle);

            foreach (string ability in creature.ruleList)
            {
                switch (ability)
                {
                    case "AttackForward":
                    case "AttackForwardContinuous":
                    case "AttackForwardRanged":
                    case "AttackForwardRangedContinuous":
                        {
                            //TODO: Relentless creatures will attack but do not continue after the first creature

                            NewEffects.Effect.Target selfTarget = new NewEffects.Effect.Target();
                            selfTarget.color    = battle.color;
                            selfTarget.position = creature.posY + "," + creature.posX;

                            NewEffects newEffects = new NewEffects();

                            int opponentCreaturePosition = BattleAPI.CreatureOnRow(opponentBattle, creature);

                            if (opponentCreaturePosition >= 0)
                            {
                                bool opponentCreatureDestroyed;

                                Creature opponentCreature = opponentBattle.board[opponentCreaturePosition, creature.posY];

                                NewEffects.Effect.Target opponentTarget = new NewEffects.Effect.Target();
                                opponentTarget.color    = opponentBattle.color;
                                opponentTarget.position = opponentCreature.posY + "," + opponentCreature.posX;

                                if (creature.currentAp > opponentCreature.currentHp)
                                {
                                    opponentCreature.currentHp = 0;
                                    opponentCreatureDestroyed  = true;
                                }
                                else
                                {
                                    opponentCreature.currentHp -= creature.currentAp;
                                    opponentCreatureDestroyed   = false;
                                }

                                NewEffects.Effect unitAttackTileEffect = new NewEffects.Effect();
                                NewEffects.Effect damageUnitEffect     = new NewEffects.Effect();
                                NewEffects.Effect statsUpdateEffect    = new NewEffects.Effect();

                                unitAttackTileEffect.UnitAttackTile        = new NewEffects.Effect.UnitAttackTileEffect();
                                unitAttackTileEffect.UnitAttackTile.source = selfTarget;
                                unitAttackTileEffect.UnitAttackTile.target = opponentTarget;

                                newEffects.effects.Add(unitAttackTileEffect);

                                damageUnitEffect.DamageUnit            = new NewEffects.Effect.DamageUnitEffect();
                                damageUnitEffect.DamageUnit.targetTile = opponentTarget;
                                damageUnitEffect.DamageUnit.amount     = creature.currentAp;
                                damageUnitEffect.DamageUnit.hp         = opponentCreature.currentHp;
                                damageUnitEffect.DamageUnit.kill       = opponentCreatureDestroyed;
                                damageUnitEffect.DamageUnit.attackType = "MELEE";    //Note: Can also be RANGED, maybe others too?
                                damageUnitEffect.DamageUnit.damageType = "PHYSICAL"; //Note: Unsure what else this can be or what difference it makes

                                newEffects.effects.Add(damageUnitEffect);

                                statsUpdateEffect.StatsUpdate    = new NewEffects.Effect.StatsUpdateEffect();
                                statsUpdateEffect.StatsUpdate.ac = opponentCreature.currentAc;
                                statsUpdateEffect.StatsUpdate.ap = opponentCreature.currentAp;
                                statsUpdateEffect.StatsUpdate.hp = opponentCreature.currentHp;

                                newEffects.effects.Add(statsUpdateEffect);

                                if (opponentCreatureDestroyed)
                                {
                                    opponentBattle.board[opponentCreature.posX, opponentCreature.posY] = null;

                                    NewEffects.Effect removeUnitEffect = new NewEffects.Effect();

                                    removeUnitEffect.RemoveUnit             = new NewEffects.Effect.RemoveUnitEffect();
                                    removeUnitEffect.RemoveUnit.removalType = "DESTROY"; //Note: Unsure what else this can be or what difference it makes
                                    removeUnitEffect.RemoveUnit.tile        = opponentTarget;

                                    newEffects.effects.Add(removeUnitEffect);
                                }
                            }
                            else
                            {
                                bool opponentIdolDestroyed;

                                NewEffects.Effect.Idol opponentIdol = new NewEffects.Effect.Idol();
                                opponentIdol.color    = opponentBattle.color;
                                opponentIdol.position = creature.posY;

                                if (creature.currentAp > opponentBattle.idols[creature.posY])
                                {
                                    opponentBattle.idols[creature.posY] = 0;

                                    opponentIdol.hp       = 0;
                                    opponentIdolDestroyed = true;
                                }
                                else
                                {
                                    opponentBattle.idols[creature.posY] -= creature.currentAp;

                                    opponentIdol.hp       = opponentBattle.idols[creature.posY];
                                    opponentIdolDestroyed = false;
                                }

                                NewEffects.Effect unitAttackIdolEffect = new NewEffects.Effect();
                                NewEffects.Effect damageIdolEffect     = new NewEffects.Effect();
                                NewEffects.Effect idolUpdateEffect     = new NewEffects.Effect();

                                unitAttackIdolEffect.UnitAttackIdol          = new NewEffects.Effect.UnitAttackIdolEffect();
                                unitAttackIdolEffect.UnitAttackIdol.attacker = selfTarget;
                                unitAttackIdolEffect.UnitAttackIdol.idol     = creature.posY;

                                newEffects.effects.Add(unitAttackIdolEffect);

                                damageIdolEffect.DamageIdol        = new NewEffects.Effect.DamageIdolEffect();
                                damageIdolEffect.DamageIdol.idol   = opponentIdol;
                                damageIdolEffect.DamageIdol.amount = creature.currentAp;
                                damageIdolEffect.DamageIdol.kill   = opponentIdolDestroyed;

                                newEffects.effects.Add(damageIdolEffect);

                                idolUpdateEffect.IdolUpdate      = new NewEffects.Effect.IdolUpdateEffect();
                                idolUpdateEffect.IdolUpdate.idol = opponentIdol;

                                newEffects.effects.Add(idolUpdateEffect);
                            }

                            if (attackingCreatureAlive)
                            {
                                NewEffects.Effect unitAttackDoneEffect = new NewEffects.Effect();

                                unitAttackDoneEffect.UnitAttackDone        = new NewEffects.Effect.UnitAttackDoneEffect();
                                unitAttackDoneEffect.UnitAttackDone.source = selfTarget;

                                newEffects.effects.Add(unitAttackDoneEffect);
                            }

                            client.Send(newEffects);
                            BattleAPI.GetOpponentClient(battle).Send(newEffects);

                            break;
                        }
                }
            }

            if (attackingCreatureAlive)
            {
                creature.currentAc = creature.defaultAc;

                BattleAPI.CreatureUpdate(client, battle, creature);
            }
        }