public void AttackMainPlayWithEnemy(Humanoid Enemy) { var power = Enemy.GetWearablePower(); var damage = 0; if (power.Strength > power.Inteligence) { damage = Enemy.GetAttackDamage(); } else { damage = Enemy.GetMagicDamage(); } Enemy.AttackOther(MainCharacter, damage); }
public void ProcessAttackScreen(Humanoid Enemy) { stats.UpdateWorld(this); while (Enemy.IsAlive() && MainCharacter.IsAlive()) { Humanoid FirstAttacker = MainCharacter.GetWearablePower().Defence <= Enemy.GetWearablePower().Defence ? MainCharacter : Enemy; Humanoid SecondAttacker = FirstAttacker == MainCharacter ? Enemy : MainCharacter; int damage = 0; if (FirstAttacker == MainCharacter) { if (GetMainCharacterAttackAnswer(out damage)) { return; } else { MainCharacter.AttackOther(Enemy, damage); } if (Enemy.IsAlive()) { AttackMainPlayWithEnemy(Enemy); } } else { AttackMainPlayWithEnemy(Enemy); if (MainCharacter.IsAlive()) { if (GetMainCharacterAttackAnswer(out damage)) { return; } else { MainCharacter.AttackOther(Enemy, damage); } } } } double distance = (new System.Windows.Point(CurrentX, CurrentY) - new System.Windows.Point(HomeTown.X, HomeTown.Y)).LengthSquared; if (distance < 0) { distance = -distance; } int Income = (int)(distance * 0.25d); if (Enemy.IsAlive()) { if (Income > 0) { MainCharacter.Orens -= Income; WriteLineColor($"You have been defeated in battle.", ConsoleColor.DarkMagenta, ConsoleColor.Black); WriteLineColor($"You woke in your bed.", ConsoleColor.DarkMagenta, ConsoleColor.Black); WriteLineColor($"{GetOrenLabel(Income)} have been deducted from your bag...", ConsoleColor.DarkMagenta, ConsoleColor.Black); WriteLineColor($"You now have {GetOrenLabel(MainCharacter.Orens)}", ConsoleColor.Yellow, ConsoleColor.Black); } CurrentLocation = Location.LocationSpot; CurrentX = HomeTown.X; CurrentY = HomeTown.Y; ActiveLocation = HomeTown; ActiveWorld.IncrementTime(12, false); } else { WriteLineColor($"You have defeated your enemy in battle!", ConsoleColor.DarkMagenta, ConsoleColor.Black); switch (Enemy.Race) { case Race.Orc: TotalOrcsDefeated += 1; break; case Race.Human: TotalHumansDefeated += 1; break; case Race.Elf: TotalElfsDefeated += 1; break; default: break; } if (Income > 0) { MainCharacter.Orens += Income; WriteLineColor($"You found {GetOrenLabel(Income)} while searching the enemies body!!!", ConsoleColor.Yellow, ConsoleColor.Black); if (Enemy.Hands != null && Percent(50)) { WriteLineColor($"You have found {Enemy.Hands.Name}.", ConsoleColor.Yellow, ConsoleColor.Black); MainCharacter.Inventory.Items.Add(WeaponItem.Clone(Enemy.Hands)); } WriteLineColor($"You now have {GetOrenLabel(MainCharacter.Orens)}", ConsoleColor.Yellow, ConsoleColor.Black); } ActiveWorld.IncrementTime(1, false); } }
public void Equipt() { if (dataInventory.SelectedRows.Count == 0) { return; } var item = (Item)dataInventory.SelectedRows[0].Cells["Item"].Value; if (ActiveHuman.Inventory.Items.Contains(item)) { if (ToSellSomething) { int price = 0; if (item is UseItem) { var itemU = (UseItem)item; price = itemU.Price; } else if (item is ToolItem) { var itemU = (ToolItem)item; price = itemU.Price; } else if (item is ResourceItem) { var itemU = (ResourceItem)item; price = itemU.Price * itemU.Quantity; } else if (item is WearableItem) { var itemW = (WearableItem)item; price = (itemW.Power.Strength + 1) * (itemW.Power.Inteligence + 1) * (itemW.Power.Defence + 1); } ActiveHuman.Orens += price; ActiveHuman.Inventory.Items.Remove(item); ToSellSomething = false; Program.WriteLineColor($"You have sold the item for {World.GetOrenLabel(price)}.", ConsoleColor.Yellow, ConsoleColor.Black); Program.WriteLineColor($"You now have {World.GetOrenLabel(ActiveHuman.Orens)}", ConsoleColor.Yellow, ConsoleColor.Black); UpdateStats(ActiveHuman); WriteLineProcess("yes"); // then we need to set the value of ToSellSomething to false. // (we set the value to false when we create the variable ToSellSomething) } else { if (item is WearableItem) { var typeofValue = item.GetType(); if (item is HeadItem) { if (ActiveHuman.Head != null) { ActiveHuman.Inventory.Items.Add(ActiveHuman.Head); ActiveHuman.Head = null; } ActiveHuman.Head = (HeadItem)item; } else if (item is ChestItem) { if (ActiveHuman.Chest != null) { ActiveHuman.Inventory.Items.Add(ActiveHuman.Chest); ActiveHuman.Chest = null; } ActiveHuman.Chest = (ChestItem)item; } else if (item is LegsItem) { if (ActiveHuman.Legs != null) { ActiveHuman.Inventory.Items.Add(ActiveHuman.Legs); ActiveHuman.Legs = null; } ActiveHuman.Legs = (LegsItem)item; } else if (item is FeetItem) { if (ActiveHuman.Feet != null) { ActiveHuman.Inventory.Items.Add(ActiveHuman.Feet); ActiveHuman.Feet = null; } ActiveHuman.Feet = (FeetItem)item; } else if (item is WeaponItem) { if (ActiveHuman.Hands != null) { ActiveHuman.Inventory.Items.Add(ActiveHuman.Hands); ActiveHuman.Hands = null; } ActiveHuman.Hands = (WeaponItem)item; } else if (item is ToolItem) { if (ActiveHuman.Belt != null) { if (!(item is QuestItem)) { ActiveHuman.Inventory.Items.Add(ActiveHuman.Belt); ActiveHuman.Belt = null; } } if (ActiveHuman.GetWearablePower().Inteligence >= ((ToolItem)item).Requirements) { if (!(item is QuestItem)) { ActiveHuman.Belt = (ToolItem)item; } else { ActiveHuman.ActivatedQuests.Add(ActiveWorld.GetRandomQuestion()); } } else { Program.WriteLineColor($"You do not meet the requirements to wear {item.Name} you require {((ToolItem)item).Requirements} Inteligence.", ConsoleColor.Red, ConsoleColor.Black); UpdateStats(ActiveHuman); return; } } ActiveHuman.Inventory.Items.Remove(item); UpdateStats(ActiveHuman); } else if (item is Fish) { if (ActiveHuman.Inventory.CanIUseResource(typeof(Fish), 1)) { ActiveHuman.Inventory.AddOrRemoveResourceItem(typeof(Fish), -1); ActiveHuman.AddHealth(10); Program.WriteLineColor("You just ate a fish and you healed 10 health.", ConsoleColor.Green, ConsoleColor.Black); UpdateStats(ActiveHuman); } else if (ActiveHuman.Belt is QuestItem) { // do we have tree seeds to complete quest if (ActiveHuman.Inventory.CanIUseResource(typeof(TreeSeeds), 25)) { ActiveHuman.Inventory.AddOrRemoveResourceItem(typeof(TreeSeeds), -25); ActiveHuman.Power.Defence += 1; ActiveHuman.Power.Inteligence += 1; ActiveHuman.Power.Strength += 1; Program.WriteLineColor("Congratulations you have completed this quest.", ConsoleColor.Green, ConsoleColor.Black); UpdateStats(ActiveHuman); } } } } } else { UpdateStats(ActiveHuman); } }
public void ProcessRandomEvent() { if (Percent(50)) // 100 / 2 = 50% { if (Percent(25)) // 100 / 4 = 25% { CurrentForestEvent = ForestEvent.Battle; var Enemies = new Humanoid(); Enemies.Gender = (Gender)random.Next(2); Enemies.Race = (Race)random.Next(3); Enemies.SetLevel(MainCharacter.CombatLevel.Value); if (Percent(50)) { Enemies.Hands = WeaponItem.Clone(Database.Weapons[random.Next(Database.Weapons.Count)]); } WriteLineColor($"You are under attack by a {Enemies.Gender} {Enemies.Race} level {Enemies.CombatLevel.Value}!!!!", ConsoleColor.Red, ConsoleColor.Black); var power = Enemies.GetWearablePower(); WriteLineColor($"this enemy has {power.Strength} strength {power.Defence} defence and {power.Inteligence} inteligence", ConsoleColor.DarkCyan, ConsoleColor.Black); ProcessAttackScreen(Enemies); if (CurrentLocation == Location.Forest) { WriteLine($"Your current location is now {CurrentX}, {CurrentY}."); } CurrentForestEvent = ForestEvent.None; stats.UpdateWorld(this); } else if (Percent(10)) { var orens = random.Next(30, 101); MainCharacter.Orens += orens; WriteLineColor($"You found {GetOrenLabel(orens)} on the ground!!!", ConsoleColor.Yellow, ConsoleColor.Black); WriteLineColor($"You now have {GetOrenLabel(MainCharacter.Orens)}", ConsoleColor.Yellow, ConsoleColor.Black); } else if (Percent(10)) { CurrentForestEvent = ForestEvent.Stranger; var person = new Humanoid(); person.Gender = (Gender)random.Next(2); person.Race = (Race)random.Next(3); person.SetRandomNewName(); person.SetLevel(random.Next(MainCharacter.CombatLevel.Value + 5)); stats.UpdateWorld(this); WriteLineColor($"Stranger approachers...\r\n i'm looking for somewhere to live", ConsoleColor.Red, ConsoleColor.Black); string input = Question("Do you want to help this stranger?", "no", "yes"); if (input == "yes") { TotalStrangersCollected += 1; WriteLine($"Sure you can come to my town {HomeTown.Name}."); WriteLine($"The Coordinates are {HomeTown.X}, {HomeTown.Y}."); int xp = 100; if (Percent(15)) { person.Smithing.AddXP(person.Smithing.GetXPToLevelUp(RandomNumber(30))); if (person.Smithing.Value > 15) { HomeTown.Buildings.Add(new Buildings() { Owner = person, Type = BuildingType.Blacksmith }); WriteLineColor($"{person.Name}, Just opened a new Blacksmith at your home town.", ConsoleColor.Yellow, ConsoleColor.Black); xp += 100; } } else if (Percent(15)) { person.Barter.AddXP(person.Barter.GetXPToLevelUp(RandomNumber(30))); if (person.Barter.Value > 10) { HomeTown.Buildings.Add(new Buildings() { Owner = person, Type = BuildingType.Store }); WriteLineColor($"{person.Name}, Just opened a new store at your home town.", ConsoleColor.Yellow, ConsoleColor.Black); xp += 100; } } WriteLineColor($"{person.Name}: Well i better get going then, Thank you so much, Catch you soon.", ConsoleColor.Yellow, ConsoleColor.Black); int orens = RandomNumber(50); if (orens > 0) { MainCharacter.Orens += orens; WriteLineColor($"Hope this helps you, {person.Name} gave you {GetOrenLabel(orens)}", ConsoleColor.Yellow, ConsoleColor.Black); WriteLineColor($"You now have {GetOrenLabel(MainCharacter.Orens)}", ConsoleColor.Yellow, ConsoleColor.Black); UpdateStats(MainCharacter); xp += 10; } MainCharacter.Barter.AddXP(xp); WriteLineColor($"You received {xp} xp for Barter Skill.", ConsoleColor.DarkCyan, ConsoleColor.Black); HomeTown.PeopleWhoLiveHere.Add(person); } else { int orens = 100; MainCharacter.Orens += orens; WriteLine("I'm a bandit, give me all your orens and you wont get hurt!"); WriteLineColor($"You stole {GetOrenLabel(orens)}!!!", ConsoleColor.Yellow, ConsoleColor.Black); WriteLineColor($"You now have {GetOrenLabel(MainCharacter.Orens)}", ConsoleColor.Yellow, ConsoleColor.Black); UpdateStats(MainCharacter); } CurrentForestEvent = ForestEvent.None; stats.UpdateWorld(this); WriteLine($"Your current location is now {CurrentX}, {CurrentY}."); } } UpdateStats(MainCharacter); }
public void UpdateStats(Humanoid livingEntity) { // InvokeRequired required compares the thread ID of the // calling thread to the thread ID of the creating thread. // If these threads are different, it returns true. if (this.InvokeRequired) { VoidWithAbility d = new VoidWithAbility(UpdateStats); this.Invoke(d, new object[] { livingEntity }); } else { ActiveHuman = livingEntity; var x = livingEntity.GetWearablePower(); this.labelStrength.Text = "Strength: " + livingEntity.Power.Strength + " / " + x.Strength; this.labelInteligence.Text = "Inteligence: " + livingEntity.Power.Inteligence + " / " + x.Inteligence; this.labelDefence.Text = "Defence: " + livingEntity.Power.Defence + " / " + x.Defence; this.labelHealth.Text = "Health: " + livingEntity.Health; this.labelXP.Text = $"XP: {livingEntity.CombatLevel.XP} / {livingEntity.CombatLevel.XPToLevelUp}"; this.labelName.Text = "Name: " + livingEntity.Name; this.labelRace.Text = "Race: " + livingEntity.Race.ToString("G"); this.labelGender.Text = "Gender: " + livingEntity.Gender.ToString("G"); this.labelTime.Text = "Time: " + ActiveWorld.TimeInDay; this.labelDay.Text = "Day: " + ActiveWorld.Day; if (livingEntity.Orens == 1) { this.labelOrens.Text = "Oren: " + livingEntity.Orens; } else { this.labelOrens.Text = "Orens: " + livingEntity.Orens; } this.labelPoints.Text = livingEntity.AvailablePowerPoints.ToString(); this.labelLevel.Text = "Level: " + livingEntity.CombatLevel.Value; UpdatePointButtons(); dataEquipt.Columns.Clear(); dataEquipt.DataSource = null; var dt = new DataTable(); dt.Columns.Add("Name", typeof(string)); dt.Columns.Add("Description", typeof(string)); dt.Columns.Add("Strength", typeof(int)); dt.Columns.Add("Inteligence", typeof(int)); dt.Columns.Add("Defence", typeof(int)); dt.Columns.Add("Location", typeof(string)); dt.Columns.Add("Item", typeof(Item)); AddRowToEquipt(dt, livingEntity.Head); AddRowToEquipt(dt, livingEntity.Chest); AddRowToEquipt(dt, livingEntity.Legs); AddRowToEquipt(dt, livingEntity.Feet); AddRowToEquipt(dt, livingEntity.Hands); AddRowToEquipt(dt, livingEntity.Belt); dt.AcceptChanges(); var dt2 = new DataTable(); dt2.Columns.Add("Name", typeof(string)); dt2.Columns.Add("Description", typeof(string)); dt2.Columns.Add("Item", typeof(Item)); foreach (Item item in livingEntity.Inventory.Items) { DataRow dr = dt2.NewRow(); string name = item.Name; if (item is ResourceItem) { name = (item as ResourceItem).Quantity + " " + name; } dr["Name"] = name; dr["Description"] = item.Description; dr["Item"] = item; dt2.Rows.Add(dr); } dt2.AcceptChanges(); dataEquipt.DataSource = dt; dataInventory.DataSource = dt2; HideAndReadOnlyDT(dataEquipt); HideAndReadOnlyDT(dataInventory); gridQuests.Columns.Clear(); gridQuests.DataSource = null; DataTable dt3 = new DataTable(); dt3.Columns.Add("Description", typeof(string)); dt3.Columns.Add("Days Old", typeof(int)); dt3.Columns.Add("quest", typeof(Quest)); foreach (Quest quest in livingEntity.ActivatedQuests) { DataRow dr = dt3.NewRow(); switch (quest.Type) { case QuestType.GatherTrees: case QuestType.GatherFish: dr["Description"] = $"Gather {quest.QuantityTillFinished} {(quest.Type == QuestType.GatherTrees ? "wood" : "fish")}"; break; case QuestType.GatherStrangers: dr["Description"] = $"Meet {quest.QuantityTillFinished} strangers and allow them to join your home town."; break; case QuestType.FightOrc: case QuestType.FightElfs: case QuestType.FightHumans: dr["Description"] = $"Defeat {quest.QuantityTillFinished} {((quest.Type == QuestType.FightOrc ? "orc" : quest.Type == QuestType.FightElfs ? "elf" : "human") + (quest.QuantityTillFinished > 1 ? "'s" : ""))} in battle."; break; } dr["quest"] = quest; dt3.Rows.Add(dr); } dt3.AcceptChanges(); gridQuests.DataSource = dt3; gridQuests.Columns["quest"].Visible = false; } }