Example #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);
        }
Example #2
0
        public static void TurnBegin(Client client, Battle battle)
        {
            battle.turn++;

            NewEffects newEffects = new NewEffects();

            NewEffects.Effect turnBeginEffect = new NewEffects.Effect();
            turnBeginEffect.TurnBegin         = new NewEffects.Effect.TurnBeginEffect();

            turnBeginEffect.TurnBegin.turn = battle.turn;

            Battle opponentBattle = GetOpponentBattle(battle);

            if (battle.turn != 1)
            {
                opponentBattle.turn++;

                if (battle.turnColor == "white")
                {
                    battle.turnColor         = "black";
                    opponentBattle.turnColor = "black";

                    turnBeginEffect.TurnBegin.color = "black";
                }
                else
                {
                    battle.turnColor         = "white";
                    opponentBattle.turnColor = "white";

                    turnBeginEffect.TurnBegin.color = "white";
                }
            }
            else { turnBeginEffect.TurnBegin.color = battle.turnColor; }

            newEffects.effects.Add(turnBeginEffect);
            client.Send(newEffects);

            if (battle.turn != 1)
            {
                GetOpponentClient(battle).Send(newEffects);
            }
        }
Example #3
0
        public static void UpdateHand(Client client, Battle battle)
        {
            NewEffects newEffects = new NewEffects();

            NewEffects.Effect handUpdateEffect = new NewEffects.Effect();
            handUpdateEffect.HandUpdate        = new NewEffects.Effect.HandUpdateEffect();

            handUpdateEffect.HandUpdate.profileId = client.account.id;

            foreach (KeyValuePair<int, Card> card in battle.handMap)
            {
                handUpdateEffect.HandUpdate.cards.Add(card.Value);
            }

            newEffects.effects.Add(handUpdateEffect);

            client.Send(newEffects);
        }
Example #4
0
        public static void ResourcesUpdate(Client client, Battle battle)
        {
            NewEffects newEffects = new NewEffects();

            NewEffects.Effect resourcesUpdateEffect = new NewEffects.Effect();
            resourcesUpdateEffect.ResourcesUpdate   = new NewEffects.Effect.ResourcesUpdateEffect();

            Battle whiteBattle; Battle blackBattle;

            if (battle.color == "white")
            {
                whiteBattle = battle;
                blackBattle = GetOpponentBattle(battle);
            }
            else
            {
                whiteBattle = GetOpponentBattle(battle);
                blackBattle = battle;
            }

            resourcesUpdateEffect.ResourcesUpdate.whiteAssets.handSize = whiteBattle.handMap.Count;
            resourcesUpdateEffect.ResourcesUpdate.blackAssets.handSize = blackBattle.handMap.Count;

            resourcesUpdateEffect.ResourcesUpdate.whiteAssets.availableResources.DECAY  = whiteBattle.resources[(int)resourceType.decay, 0];
            resourcesUpdateEffect.ResourcesUpdate.whiteAssets.availableResources.ENERGY = whiteBattle.resources[(int)resourceType.energy, 0];
            resourcesUpdateEffect.ResourcesUpdate.whiteAssets.availableResources.GROWTH = whiteBattle.resources[(int)resourceType.growth, 0];
            resourcesUpdateEffect.ResourcesUpdate.whiteAssets.availableResources.ORDER  = whiteBattle.resources[(int)resourceType.order, 0];
            resourcesUpdateEffect.ResourcesUpdate.whiteAssets.outputResources.DECAY     = whiteBattle.resources[(int)resourceType.decay, 1];
            resourcesUpdateEffect.ResourcesUpdate.whiteAssets.outputResources.ENERGY    = whiteBattle.resources[(int)resourceType.energy, 1];
            resourcesUpdateEffect.ResourcesUpdate.whiteAssets.outputResources.GROWTH    = whiteBattle.resources[(int)resourceType.growth, 1];
            resourcesUpdateEffect.ResourcesUpdate.whiteAssets.outputResources.ORDER     = whiteBattle.resources[(int)resourceType.order, 1];

            resourcesUpdateEffect.ResourcesUpdate.blackAssets.availableResources.DECAY  = blackBattle.resources[(int)resourceType.decay, 0];
            resourcesUpdateEffect.ResourcesUpdate.blackAssets.availableResources.ENERGY = blackBattle.resources[(int)resourceType.energy, 0];
            resourcesUpdateEffect.ResourcesUpdate.blackAssets.availableResources.GROWTH = blackBattle.resources[(int)resourceType.growth, 0];
            resourcesUpdateEffect.ResourcesUpdate.blackAssets.availableResources.ORDER  = blackBattle.resources[(int)resourceType.order, 0];
            resourcesUpdateEffect.ResourcesUpdate.blackAssets.outputResources.DECAY     = blackBattle.resources[(int)resourceType.decay, 1];
            resourcesUpdateEffect.ResourcesUpdate.blackAssets.outputResources.ENERGY    = blackBattle.resources[(int)resourceType.energy, 1];
            resourcesUpdateEffect.ResourcesUpdate.blackAssets.outputResources.GROWTH    = blackBattle.resources[(int)resourceType.growth, 1];
            resourcesUpdateEffect.ResourcesUpdate.blackAssets.outputResources.ORDER     = blackBattle.resources[(int)resourceType.order, 1];

            newEffects.effects.Add(resourcesUpdateEffect);

            client.Send(newEffects);
            GetOpponentClient(battle).Send(newEffects);
        }
Example #5
0
        public static void Surrender(Client client)
        {
            client.packetMap.Remove("Surrender");

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

            if (battle.phase != "End")
            {
                Battle.Stats whiteStats; Battle.Stats blackStats;
                string whiteProfileId; string blackProfileId;

                Battle opponentBattle = BattleAPI.GetOpponentBattle(battle);
                Client opponentClient = BattleAPI.GetOpponentClient(battle);

                battle.phase         = "End";
                opponentBattle.phase = "End";

                NewEffects newEffects = new NewEffects();

                NewEffects.Effect surrenderEffectEffect = new NewEffects.Effect();
                NewEffects.Effect endGameEffect         = new NewEffects.Effect();

                surrenderEffectEffect.SurrenderEffect       = new NewEffects.Effect.SurrenderEffectEffect();
                surrenderEffectEffect.SurrenderEffect.color = battle.color;

                endGameEffect.EndGame        = new NewEffects.Effect.EndGameEffect();
                endGameEffect.EndGame.winner = opponentBattle.color;

                if (battle.color == "white")
                {
                    whiteProfileId = client.account.id;
                    blackProfileId = "";

                    whiteStats = battle.stats;
                    blackStats = opponentBattle.stats;
                }
                else
                {
                    whiteProfileId = "";
                    blackProfileId = client.account.id;

                    whiteStats = opponentBattle.stats;
                    blackStats = battle.stats;
                }

                endGameEffect.EndGame.whiteStats.profileId          = whiteProfileId;
                endGameEffect.EndGame.whiteStats.idolDamage         = whiteStats.idolDamage;
                endGameEffect.EndGame.whiteStats.unitDamage         = whiteStats.unitDamage;
                endGameEffect.EndGame.whiteStats.unitsPlayed        = whiteStats.unitsPlayed;
                endGameEffect.EndGame.whiteStats.spellsPlayed       = whiteStats.spellsPlayed;
                endGameEffect.EndGame.whiteStats.enchantmentsPlayed = whiteStats.enchantmentsPlayed;
                endGameEffect.EndGame.whiteStats.scrollsDrawn       = whiteStats.scrollsDrawn;
                endGameEffect.EndGame.whiteStats.totalMs            = 0;
                endGameEffect.EndGame.whiteStats.mostDamageUnit     = 0;
                endGameEffect.EndGame.whiteStats.idolsDestroyed     = 0;

                endGameEffect.EndGame.blackStats.profileId          = blackProfileId;
                endGameEffect.EndGame.blackStats.idolDamage         = blackStats.idolDamage;
                endGameEffect.EndGame.blackStats.unitDamage         = blackStats.unitDamage;
                endGameEffect.EndGame.blackStats.unitsPlayed        = blackStats.unitsPlayed;
                endGameEffect.EndGame.blackStats.spellsPlayed       = blackStats.spellsPlayed;
                endGameEffect.EndGame.blackStats.enchantmentsPlayed = blackStats.enchantmentsPlayed;
                endGameEffect.EndGame.blackStats.scrollsDrawn       = blackStats.scrollsDrawn;
                endGameEffect.EndGame.blackStats.totalMs            = 0;
                endGameEffect.EndGame.blackStats.mostDamageUnit     = 0;
                endGameEffect.EndGame.blackStats.idolsDestroyed     = 0;

                endGameEffect.EndGame.whiteGoldReward.matchReward           = 0;
                endGameEffect.EndGame.whiteGoldReward.matchCompletionReward = 0;
                endGameEffect.EndGame.whiteGoldReward.idolsDestroyedReward  = 0;
                endGameEffect.EndGame.whiteGoldReward.totalReward           = 0;

                endGameEffect.EndGame.blackGoldReward.matchReward           = 0;
                endGameEffect.EndGame.blackGoldReward.matchCompletionReward = 0;
                endGameEffect.EndGame.blackGoldReward.idolsDestroyedReward  = 0;
                endGameEffect.EndGame.blackGoldReward.totalReward           = 0;

                newEffects.effects.Add(surrenderEffectEffect);
                newEffects.effects.Add(endGameEffect);

                client.Send(newEffects);
                opponentClient.Send(newEffects);
            }
            else
            {
                Console.WriteLine("{0} tried to surrender in a game that has already finished!", client.account.username);
            }
        }
Example #6
0
        public static void SacrificeCard(Client client, string jsonPacketData)
        {
            client.packetMap.Remove("SacrificeCard");

            SacrificeCard sacrificeCard = JsonConvert.DeserializeObject<SacrificeCard>(jsonPacketData);

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

            if (battle.handMap.ContainsKey(sacrificeCard.card))
            {
                battle.handMap.Remove(sacrificeCard.card);

                if (sacrificeCard.resource == "cards")
                {
                    CardAPI.DrawCard(battle, 2);
                }
                else
                {
                    BattleAPI.IncreaseResource(battle, sacrificeCard.resource, 1);
                }

                BattleAPI.ResourcesUpdate(client, battle);
                BattleAPI.UpdateHand(client, battle);

                NewEffects newEffects = new NewEffects();
                NewEffects.Effect cardSacrificedEffect = new NewEffects.Effect();

                cardSacrificedEffect.CardSacrificed          = new NewEffects.Effect.CardSacrificedEffect();
                cardSacrificedEffect.CardSacrificed.color    = battle.color;
                cardSacrificedEffect.CardSacrificed.resource = sacrificeCard.resource.ToUpper();

                newEffects.effects.Add(cardSacrificedEffect);

                BattleAPI.GetOpponentClient(battle).Send(newEffects);
            }
            else
            {
                Console.WriteLine("{0} tried to sacrifice the card {1} which they don't have in hand!", client.account.username, sacrificeCard.card);
            }
        }
Example #7
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);
            }
        }
Example #8
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);
            }
        }