public static int CreatureOnRow(Battle opponentBattle, Creature creature) { for (int i = 0; i < 3; i++) { if (opponentBattle.board[i, creature.posY] != null) { return i; } } return -1; }
public static void CreatureAttack(Client client, Battle battle) { for (int i = 0; i < 5; i++) { for (int ii = 0; ii < 3; ii++) { Creature creature = battle.board[ii, i]; if (creature != null) { if (creature.canTick && creature.currentAc == 0) { RuleHandler.HandleCreatureStructureAttack(client, ref creature, battle); } } } } }
public static void CreatureTick(Client client, Battle battle) { for (int i = 0; i < 5; i++) { for (int ii = 0; ii < 3; ii++) { Creature creature = battle.board[ii, i]; if (creature != null) { if (creature.canTick) { creature.currentAc--; CreatureUpdate(client, battle, creature); } } } } }
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); }
public static void DrawCard(Battle battle, int cardCount) { for (int i = 0; i < cardCount; i++) { if (battle.deck.cards.Count == 0) { foreach (KeyValuePair<int, Card> card in battle.discardMap) { battle.deck.cards.Add(card.Value); battle.discardMap.Remove(card.Key); } ShuffleDeck(battle.deck); } Card drawnCard = battle.deck.cards[0]; battle.deck.cards.Remove(drawnCard); battle.handMap.Add(drawnCard.id, drawnCard); } }
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); }
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); } }
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); } }
public static void ResetResources(Battle battle) { battle.resources[(int)resourceType.decay, 0] = battle.resources[(int)resourceType.decay, 1]; battle.resources[(int)resourceType.energy, 0] = battle.resources[(int)resourceType.energy, 1]; battle.resources[(int)resourceType.growth, 0] = battle.resources[(int)resourceType.growth, 1]; battle.resources[(int)resourceType.order, 0] = battle.resources[(int)resourceType.order, 1]; }
public static void Message(Battle battle, string from, string msg) { GameChatMessage gameChatMessage = new GameChatMessage(); gameChatMessage.from = from; gameChatMessage.text = msg; BattleAPI.GetOpponentClient(battle).Send(gameChatMessage); }
public static Client GetOpponentClient(Battle battle) { return Variables.sessionMap[battle.opponent]; }
public static Battle GetOpponentBattle(Battle battle) { return Variables.battleMap[battle.opponent]; }
public static bool EnoughResources(Battle battle, CardType cardType) { if (cardType.costDecay != 0) { if (battle.resources[(int)resourceType.decay, 0] >= cardType.costDecay) { return true; } } else if (cardType.costEnergy != 0) { if (battle.resources[(int)resourceType.energy, 0] >= cardType.costEnergy) { return true; } } else if (cardType.costGrowth != 0) { if (battle.resources[(int)resourceType.growth, 0] >= cardType.costGrowth) { return true; } } else if (cardType.costOrder != 0) { if (battle.resources[(int)resourceType.order, 0] >= cardType.costOrder) { return true; } } return false; }
public static void HandleCreatureStructureSummon(Client client, ref Creature creature, Battle battle) { foreach (string ability in creature.ruleList) { switch (ability) { case "DrawScrollOnEnterBoard": { CardAPI.DrawCard(battle, 1); break; } case "GravelockStrengthModifier": { foreach (Creature otherCreature in battle.board) { if (otherCreature != null) { if (creature != otherCreature && otherCreature.subTypes.Contains("Gravelock")) { otherCreature.currentAp++; otherCreature.currentHp++; BattleAPI.CreatureUpdate(client, battle, otherCreature); } } } break; } case "GreatWolfStrengthModifier": { foreach (Creature otherCreature in battle.board) { if (creature != otherCreature && otherCreature.subTypes.Contains("Wolf")) { creature.currentAp++; } } break; } case "Haste": { creature.currentAc = 0; break; } case "IncOutputEnergy": { BattleAPI.IncreaseResource(battle, "energy", 1); break; } case "IncOutputGrowth": { BattleAPI.IncreaseResource(battle, "growth", 1); break; } case "IncOutputOrder": { BattleAPI.IncreaseResource(battle, "order", 1); break; } case "NighthawkIncAp": { foreach (Creature otherCreature in battle.board) { if (creature != otherCreature && otherCreature.subTypes.Contains("Gravelock")) { creature.currentAp++; } } break; } case "RatHealthModifier": { foreach (Creature otherCreature in battle.board) { if (otherCreature != null) { if (creature != otherCreature && otherCreature.subTypes.Contains("Rat")) { otherCreature.currentHp++; BattleAPI.CreatureUpdate(client, battle, otherCreature); } } } break; } case "ShrineIncHp": { foreach (Creature otherCreature in battle.board) { if (otherCreature != null) { otherCreature.currentHp += 1; BattleAPI.CreatureUpdate(client, battle, otherCreature); } } break; } case "TotemPower": { foreach (Creature otherCreature in battle.board) { if (otherCreature != null) { otherCreature.currentAp += 1; BattleAPI.CreatureUpdate(client, battle, otherCreature); } } break; } } } }
public static void DecreaseResource(Battle battle, string resource, int amount) { switch (resource.ToLower()) { case "decay": { battle.resources[(int)resourceType.decay, 0] -= amount; break; } case "energy": { battle.resources[(int)resourceType.energy, 0] -= amount; break; } case "growth": { battle.resources[(int)resourceType.growth, 0] -= amount; break; } case "order": { battle.resources[(int)resourceType.order, 0] -= amount; break; } } }
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); }
public static void GameChallengeAccept(Client client, string jsonPacketData) { client.packetMap.Remove("GameChallengeAccept"); GameChallengeAccept gameChallengeAccept = JsonConvert.DeserializeObject<GameChallengeAccept>(jsonPacketData); Client opponentSession = PlayerAPI.GetSession(gameChallengeAccept.profile, true); if (opponentSession.account.challengeMap.ContainsKey(client.account.username)) { if (client.account.deckMap.ContainsKey(gameChallengeAccept.deck)) { Battle battle = new Battle() { gameType = "MP_QUICKMATCH", opponent = opponentSession.account.username, deck = client.account.deckMap[gameChallengeAccept.deck] }; Battle opponentBattle = new Battle() { gameType = "MP_QUICKMATCH", opponent = client.account.username, deck = opponentSession.account.deckMap[opponentSession.account.challengeMap[client.account.username]] }; if (new Random().Next(2) == 0) { battle.color = "white"; opponentBattle.color = "black"; } else { battle.color = "black"; opponentBattle.color = "white"; } if (new Random().Next(2) == 0) { battle.turnColor = "white"; opponentBattle.turnColor = "white"; } else { battle.turnColor = "black"; opponentBattle.turnColor = "black"; } Variables.battleMap.Add(client.account.username, battle); Variables.battleMap.Add(opponentSession.account.username, opponentBattle); BattleAPI.Redirect(client); BattleAPI.Redirect(opponentSession); opponentSession.account.challengeMap.Remove(client.account.username); } else { Console.WriteLine("{0} is trying to repsond to {1} with the deck {2} which they don't own!", client.account.username, opponentSession.account.username, gameChallengeAccept.deck); PlayerAPI.KickPlayer(client, "AntiCheat: You have been disconnected from the server!"); } } else { Console.WriteLine("{0} tried to respond to a game challenge that was never sent!"); PlayerAPI.KickPlayer(client, "AntiCheat: You have been disconnected from the server!"); } }
public static List<CardInfo.Data.SelectableTiles.TileSet> HandleCardSelect(Battle battle, CardType cardType) { List<CardInfo.Data.SelectableTiles.TileSet> tileSets = new List<CardInfo.Data.SelectableTiles.TileSet>(); Battle opponentBattle = BattleAPI.GetOpponentBattle(battle); foreach (string ability in cardType.rulesList) { switch (ability) { //Select all creatures and structures on both sides of the board case "Animovore": case "Atrophy": case "BearPaw": case "BlessingOfHaste": case "Bloodboil": case "Burn": case "ChampionRing": case "ClusterHex": case "CrownOfStrength": case "CurseAttacker": case "DamageOneOnDamage": case "ElanVital": case "EmberBonds": case "Focus": case "FrostWind": case "Hymn": case "IllthornSeed": case "IronWhip": case "Kabonk": case "Languid": case "MagmaPack": case "MireCurse": case "PlateArmor": case "Plating": case "Pother": case "PotionOfResistance": case "Regeniture": case "ResonantHelm": case "Spark": case "Speed": case "StagHeart": case "ThoughtTrap": case "ThunderSurge": case "ViolentDispersal": case "VitriolAura": { for (int i = 0; i < 5; i++) { for (int ii = 0; ii < 3; ii++) { if (battle.board[ii, i] != null) { TileSet(tileSets, battle.color, ii, i); } if (opponentBattle.board[ii, i] != null) { TileSet(tileSets, opponentBattle.color, ii, i); } } } break; } //Select all creatures on both sides of the board case "BindingRoot": case "BlastStrike": case "BlindRage": case "BrainLice": case "DamningCurse": case "DeathCapBerserk": case "DecCountdownOnCreatureDeathEnch": case "Desperation": case "DivineMark": case "DryadicPower": case "EnergySiphon": case "HexMarks": case "InfectiousBlight": case "LeechingRing": case "MetalHeart": case "Pestis": case "RangersBane": case "Redesign": case "RoastedBeanPotion": case "ShroudOfUnlife": case "UnleashInnerPower": { for (int i = 0; i < 5; i++) { for (int ii = 0; ii < 3; ii++) { Creature creature = battle.board[ii, i]; Creature opponentCreature = opponentBattle.board[ii, i]; if (creature != null && creature.kind == "CREATURE") { TileSet(tileSets, battle.color, ii, i); } if (opponentCreature != null && opponentCreature.kind == "CREATURE") { TileSet(tileSets, opponentBattle.color, ii, i); } } } break; } //Select all structures on both sides of the board case "Overdrive": case "Rigged": case "TickBomb": { for (int i = 0; i < 5; i++) { for (int ii = 0; ii < 3; ii++) { Creature creature = battle.board[ii, i]; Creature opponentCreature = opponentBattle.board[ii, i]; if (creature != null && creature.kind == "STRUCTURE") { TileSet(tileSets, battle.color, ii, i); } if (opponentCreature != null && opponentCreature.kind == "STRUCTURE") { TileSet(tileSets, opponentBattle.color, ii, i); } } } break; } //Select all creatures and structures on your side of the board case "FaithBlessing": case "Metempsychosis": case "Nutrition": { for (int i = 0; i < 5; i++) { for (int ii = 0; ii < 3; ii++) { if (battle.board[ii, i] != null) { TileSet(tileSets, battle.color, ii, i); } } } break; } //Select all creatures on your side of the board case "Callback": case "FertileSoil": case "GrislyGraft": { for (int i = 0; i < 5; i++) { for (int ii = 0; ii < 3; ii++) { Creature creature = battle.board[ii, i]; if (creature != null && creature.kind == "CREATURE") { TileSet(tileSets, battle.color, ii, i); } } } break; } //Select all creatures and structures on your opponents side of the board case "Pushback": { for (int i = 0; i < 5; i++) { for (int ii = 0; ii < 3; ii++) { if (opponentBattle.board[ii, i] != null) { TileSet(tileSets, battle.color, ii, i); } } } break; } } } return tileSets; }