protected override void OnKilledTarget(Creature target) { base.OnKilledTarget(target); // Death message var nonPlayer = (NonPlayer)target; var message = Strings.GetNpcDeathMessage(target.Name); TJ.GameLog(message); // Experience award Experience += nonPlayer.Info.Experience; message = Strings.GetExpMessage(nonPlayer.Info.Experience); TJ.GameLog(message); // Generate loot var loot = nonPlayer.Info.Loot; if (loot != null && loot.Count > 0) { foreach (var lootEntry in loot) { var success = MathUtils.RollPercentage(lootEntry.Rate); if (success) { var item = new Item(lootEntry.ItemInfo); target.Tile.Inventory.Add(item, 1); } } } target.Remove(); }
protected override void OnEntered() { base.OnEntered(); if (Map.DungeonLevel == null) { TJ.GameLog(Strings.BuildEnteredMap(Map.Name)); } else { TJ.GameLog(Strings.BuildEnteredMap(Map.Name + ", " + Map.DungeonLevel.Value)); } }
protected override void OnPositionChanged() { base.OnPositionChanged(); if (Tile == null || Tile.Inventory.Items.Count == 0) { return; } if (Tile.Inventory.Items.Count == 1) { TJ.GameLog(Strings.BuildItemLyingOnTheFloor(Tile.Inventory.Items[0].Item.Info.Name)); } else { TJ.GameLog(Strings.SomeItemsAreLying); } }
public void UpdateTilesVisibility(bool refreshMap = false) { var map = Player.Map; // Reset IsInFov for the whole map for (var x = 0; x < map.Width; ++x) { for (var y = 0; y < map.Height; ++y) { map[x, y].IsInFov = false; } } map.FieldOfView.Calculate(Player.Position.X, Player.Position.Y, 12); foreach (var coord in map.FieldOfView.CurrentFOV) { var tile = map[coord]; tile.IsInFov = true; if (!tile.IsExplored) { refreshMap = true; tile.IsExplored = true; } if (tile.Creature != null) { var asNpc = tile.Creature as NonPlayer; if (asNpc != null && asNpc.Info.CreatureType == CreatureType.Enemy && asNpc.AttackTarget == null) { TJ.GameLog(Strings.BuildRushesToAttack(asNpc.Info.Name)); asNpc.AttackTarget = TJ.Player; } } } if (refreshMap) { MapNavigationBase.InvalidateImage(); } }
public void UseAbility(AbilityInfo ability) { if (Player.Stats.Life.CurrentMana < ability.Mana) { TJ.GameLog(Strings.NotEnoughEnergy); return; } var success = true; foreach (var effect in ability.Effects) { var asHealSelf = effect as HealSelf; if (asHealSelf != null) { var amount = (float)MathUtils.Random.Next(asHealSelf.Minimum, asHealSelf.Maximum + 1); if (Player.Stats.Life.CurrentHP >= Player.Stats.Life.MaximumHP) { TJ.GameLog(Strings.MaximumHpAlready); success = false; continue; } else if (Player.Stats.Life.CurrentHP + amount > Player.Stats.Life.MaximumHP) { amount = Player.Stats.Life.MaximumHP - Player.Stats.Life.CurrentHP; } Player.Stats.Life.CurrentHP += amount; var message = string.Format(asHealSelf.MessageActivated, amount); TJ.GameLog(message); } } if (success) { Player.Stats.Life.CurrentMana -= ability.Mana; WorldAct(); } }
public void Attack(Creature target) { var battleStats = Stats.Battle; var attacks = battleStats.Attacks; if (attacks == null || attacks.Length == 0) { return; } foreach (var attack in attacks) { var armorClass = target.Stats.Battle.ArmorClass; var attackRoll = 50 + battleStats.HitRoll * 8 - armorClass; Debug.WriteLine("{0} against {1}'s attack roll is {2}", Name, target.Name, attackRoll); var damage = MathUtils.Random.Next(attack.MinDamage, attack.MaxDamage + 1); if (!MathUtils.RollPercentage(attackRoll) || damage <= 0) { // Miss var message = Strings.GetMissMessage(Name, target.Name, attack.AttackType); TJ.GameLog(message); } else { target.Stats.Life.CurrentHP -= damage; var message = Strings.GetAttackMessage(damage, Name, target.Name, attack.AttackType); TJ.GameLog(message); if (target.Stats.Life.CurrentHP <= 0 && target != TJ.Player) { OnKilledTarget(target); break; } } } }
protected override void OnItemTaken(Item item, int count) { base.OnItemTaken(item, count); TJ.GameLog(Strings.BuildPickedUp(item.Info.Name, count)); }
private bool ProcessMovementCreature(Point newPos) { var player = TJ.Player; var asNpc = player.Map[newPos].Creature as NonPlayer; if (asNpc == null) { return(false); } var handled = true; switch (asNpc.Info.CreatureType) { case CreatureType.Merchant: // Initiate trade var dialog = new TradeDialog(player, asNpc); dialog.ShowModal(Desktop); break; case CreatureType.Instructor: Dialog messageBox; if (player.Level < TJ.Module.MaximumLevel) { var nextLevel = TJ.Module.LevelCosts[player.Level + 1]; if (nextLevel.Experience <= player.Experience && nextLevel.Gold <= player.Gold) { var str = Strings.BuildNextLevelOffer(player.Experience, player.Gold, nextLevel.Experience, nextLevel.Gold); messageBox = Dialog.CreateMessageBox(Strings.InstructorCaption, str); messageBox.Closed += (s, a) => { if (!messageBox.Result) { return; } // Level up player.Experience -= nextLevel.Experience; player.Gold -= nextLevel.Gold; player.Level++; TJ.GameLog(Strings.BuildNextLevel(player.Level, player.ClassPointsLeft)); }; } else { var str = Strings.BuildNextLevelRequirements(player.Experience, player.Gold, nextLevel.Experience, nextLevel.Gold); messageBox = Dialog.CreateMessageBox(Strings.InstructorCaption, str); messageBox.ButtonCancel.Visible = false; } } else { messageBox = Dialog.CreateMessageBox(Strings.InstructorCaption, Strings.ReachedMaximumLevel); messageBox.ButtonCancel.Visible = false; } messageBox.DragDirection = DragDirection.None; messageBox.ShowModal(Desktop); break; default: handled = false; break; } return(handled); }