public static SkillLevelsComponent ApplyStatModifications(StateSpaceComponents spaceComponents, Guid entity, SkillLevelsComponent originalStats) { SkillLevelsComponent newStats = originalStats; //See if the entity has an inventory to check for artifact modifications if(spaceComponents.InventoryComponents.ContainsKey(entity)) { InventoryComponent entityInventory = spaceComponents.InventoryComponents[entity]; //For each artifact in the entity' inventory, look for the statmodificationcomponent, and modify stats accordingly. foreach (Guid id in entityInventory.Artifacts) { Entity inventoryItem = spaceComponents.Entities.Where(x => x.Id == id).FirstOrDefault(); if (inventoryItem != null && (inventoryItem.ComponentFlags & ComponentMasks.Artifact) == ComponentMasks.Artifact) { StatModificationComponent statsMods = spaceComponents.StatModificationComponents[id]; newStats.Accuracy = (newStats.Accuracy + statsMods.AccuracyChange < 0) ? 0 : newStats.Accuracy + statsMods.AccuracyChange; newStats.Defense = (newStats.Defense + statsMods.DefenseChange < 0) ? 0 : newStats.Defense + statsMods.DefenseChange; newStats.DieNumber = (newStats.DieNumber + statsMods.DieNumberChange < 1) ? 1 : newStats.DieNumber + statsMods.DieNumberChange; newStats.Health = (newStats.Health + statsMods.HealthChange < 0) ? 0 : newStats.Health + statsMods.HealthChange; newStats.MaximumDamage = (newStats.MaximumDamage + statsMods.MaximumDamageChange < 1) ? 1 : newStats.MaximumDamage + statsMods.MaximumDamageChange; newStats.MinimumDamage = (newStats.MinimumDamage + statsMods.MinimumDamageChange < 1) ? 1 : newStats.MinimumDamage + statsMods.MinimumDamageChange; } } } return newStats; }
public PlayingState(IStateSpace space, Camera camera, ContentManager content, GraphicsDeviceManager graphics, IState prevState = null, MouseState mouseState = new MouseState(), GamePadState gamePadState = new GamePadState(), KeyboardState keyboardState = new KeyboardState(), DungeonInfo saveInfo = null) { this.Content = new ContentManager(content.ServiceProvider, "Content"); Graphics = graphics; PrevMouseState = mouseState; PrevGamepadState = gamePadState; PrevKeyboardState = keyboardState; SkillLevelsComponent newPlayerStats = new SkillLevelsComponent() { CurrentHealth = 100, Health = 100, Accuracy = 100, Defense = 10, Wealth = 0, MinimumDamage = 1, MaximumDamage = 3, DieNumber = 1 }; StateComponents = saveInfo == null ? new StateComponents() { PlayerSkillLevels = newPlayerStats } : saveInfo.stateComponents; SetStateSpace(space, camera, saveInfo == null); previousState = prevState; }
public static int CalculateMeleeDamage(StateSpaceComponents spaceComponents, SkillLevelsComponent attackingStats, Guid attacker) { attackingStats = InventorySystem.ApplyStatModifications(spaceComponents, attacker, attackingStats); int damage = 0; for(int i = 0; i < attackingStats.DieNumber; i++) { damage += spaceComponents.random.Next((int)(attackingStats.MinimumDamage / attackingStats.DieNumber), (int)(attackingStats.MaximumDamage / attackingStats.DieNumber) + 1); } return damage; }
public static double CalculateAccuracy(StateSpaceComponents spaceComponents, SkillLevelsComponent attacker, Guid attackerId, SkillLevelsComponent defender, Guid defenderId) { attacker = InventorySystem.ApplyStatModifications(spaceComponents, attackerId, attacker); defender = InventorySystem.ApplyStatModifications(spaceComponents, defenderId, defender); return attacker.Accuracy * (Math.Pow(.95, defender.Defense)); }