//Creates an ItemSet to assign to Ammo public void EquipAmmo(Ammo a) { this.Ammo = ItemHelper.getItemSet(inventory, a); }
public static GameCharacter getGameCharacterFromGameCharacterData(GameCharacterData data, GameDataSet gameDataSet) { GameCharacter character = new GameCharacter() { level = data.level, ac = data.ac, ap = data.ap, attack = data.attack, characterSpriteIndex = data.characterSpriteIndex, characterSpritesheetName = data.characterSpritesheetName, hp = data.hp, displayChar = data.displayChar, name = data.name, portraitSpriteIndex = data.portraitSpriteIndex, portraitSpritesheetName = data.portraitSpritesheetName, totalAP = data.ap, totalHP = data.hp, type = data.type, x = 0, y = 0, strength = data.strength, agility = data.agility, endurance = data.endurance, spirit = data.spirit, xp = ExperienceHelper.getXPAtLevel(data.level), talentPoints = 0, statPoints = 0 }; if (data.abilityList.Count > 0) { List <Ability> abilityList = new List <Ability>(); foreach (var l in data.abilityList) { if (gameDataSet.abilityDataDictionary.ContainsKey(l)) { abilityList.Add(AbilityFactory.getAbilityFromAbilityData(gameDataSet.abilityDataDictionary[l], gameDataSet.effectDataDictionary)); } } character.abilityList = abilityList; } if (data.inventory.Count > 0) { List <Item> itemList = new List <Item>(); foreach (var i in data.inventory) { Item tempItem = ItemFactory.getItemFromIndex(i, gameDataSet); if (tempItem != null) { if (tempItem.type == ItemType.Ammo) { character.inventory.Add(tempItem); character.Ammo = ItemHelper.getItemSet(character.inventory, tempItem); } else { itemList.Add(tempItem); } } } character.usableItemList = itemList; //character.inventory = itemList; } if (data.equippedArmor.Count > 0) { List <Armor> armorList = new List <Armor>(); foreach (var a in data.equippedArmor) { if (gameDataSet.armorDataDictionary.ContainsKey(a)) { armorList.Add(ItemFactory.getArmorFromArmorData(gameDataSet.armorDataDictionary[a], gameDataSet.abilityDataDictionary, gameDataSet.effectDataDictionary)); } } character.equippedArmor = armorList; } if (data.weapon > 0) { Item i = ItemFactory.getItemFromIndex(data.weapon, gameDataSet); Weapon w = (Weapon)ItemFactory.getItemFromIndex(data.weapon, gameDataSet); if (w.weaponType == WeaponType.OneHandRanged || w.weaponType == WeaponType.TwoHandRanged) { w = (RangedWeapon)w; } character.weapon = w; } if (data.activeEffects.Count > 0) { List <ActiveEffect> aeList = new List <ActiveEffect>(); foreach (long l in data.activeEffects) { if (gameDataSet.effectDataDictionary.ContainsKey(l)) { aeList.Add(AbilityFactory.getActiveEffectFromEffectData(gameDataSet.effectDataDictionary[l])); } } character.activeEffects = aeList; } if (data.passiveEffects.Count > 0) { List <PassiveEffect> peList = new List <PassiveEffect>(); foreach (long l in data.passiveEffects) { if (gameDataSet.effectDataDictionary.ContainsKey(l)) { peList.Add(AbilityFactory.getPassiveEffectFromEffectData(gameDataSet.effectDataDictionary[l])); } } character.passiveEffects = peList; } if (data.type == CharacterType.Enemy) { character = getEnemyFromGameCharacter(character, data.enemyType); } return(character); }
public static bool RangedAttack(GameCharacter attacker, GameCharacter defender, Tile targetTile, BattleGame game) { bool retval = false; //check for ranged weapon if (attacker.weapon is RangedWeapon) { RangedWeapon w = (RangedWeapon)attacker.weapon; Ammo a = (Ammo)ItemHelper.getFirstItemWithID(attacker.inventory, attacker.Ammo.itemID); //check we have ammo if (attacker.Ammo != null && attacker.Ammo.count > 0 && a.ammoType == w.ammoType) { List <Tile> tileLOSList = game.board.getBoardLOS(game.ActiveTile, targetTile); //check LOS //check range if (tileLOSList[tileLOSList.Count - 1] == targetTile) { if (tileLOSList.Count <= w.range) { if (attacker.SpendAP(attacker.weapon.actionPoints)) { var attackerPos = new UnityEngine.Vector3(attacker.x, -attacker.y); var targetPos = new UnityEngine.Vector3(defender.x, -defender.y); game.gameControllerScript.StartTempSpriteProjectile(attackerPos, targetPos, GameConstants.rangedAttackSpritesheet, GameConstants.rangedAttackSpriteindex); //check for hit if (game.r.Next(20) + attacker.attack > defender.ac) { retval = Hit(attacker, defender, game, a); //remove ammo attacker.inventory.Remove(a); attacker.Ammo = ItemHelper.getItemSet(attacker.inventory, a); retval = true; } else { game.battleLog.AddEntry(string.Format("{0} missed {1}.", attacker.name, defender.name)); } } } else { game.battleLog.AddEntry(string.Format("{0} is out of range.", defender.name)); } } else { game.battleLog.AddEntry(string.Format("Unable to hit {0}", defender.name)); } } else { game.battleLog.AddEntry(string.Format("{0} requires {1} ammo equipped", w.name, w.ammoType)); } } else { game.battleLog.AddEntry(string.Format("Equip a ranged weapon for ranged attack")); } return(retval); }