Skip to content

Instantly share code, notes, and snippets.

@ScottLilly
Last active Jan 28, 2018
Embed
What would you like to do?
SaneSam fix for monster appearance chance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Engine
{
public class Location
{
private readonly SortedList<int, int> _monsterAtLocation = new SortedList<int, int>();
public int ID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public _items Itemrequiredtoenter { get; set; }
public int MonsterAppearanceChance { get; set; }
public Quest QuestAvailableHere { get; set; }
public Vendortron9000 Vending { get; set; }
public Location LocationToNorth { get; set; }
public Location LocationToEast { get; set; }
public Location LocationToSouth { get; set; }
public Location LocationToWest { get; set; }
public bool HasAmonster { get { return _monsterAtLocation.Count > 0; } }
public bool hasAQuest { get { return QuestAvailableHere != null; } }
public bool NoReqiredItemToEnter { get { return Itemrequiredtoenter == null; } }
public Location(int id, string name, string description,_items itemrequired = null,
Quest questfind= null)
{
ID = id;
Name = name;
Description = description;
Itemrequiredtoenter = itemrequired;
QuestAvailableHere = questfind;
}
public void AddMonster(int MonsterID, int percentageOfApperance)
{
if(_monsterAtLocation.ContainsKey(MonsterID))
{
_monsterAtLocation[MonsterID] = percentageOfApperance;
}
else
{
_monsterAtLocation.Add(MonsterID, percentageOfApperance);
}
}
public Monster NewInstanceOfMonsterLivingHere()
{
if(!HasAmonster)
{
return null;
}
// If this location only has a monster appear some of the times,
// check if a monster should appear this time.
if(MonsterAppearanceChance > 0)
{
// Gets a random number between 1 and 100.
// If the number is less than, or equal to, the MonsterAppearanceChance, create a monster
bool monsterAppeared = RandomNumberGen.NumberBetween(1, 100) <= MonsterAppearanceChance;
// If no monster appeared, return null (no monster this time)
if(!monsterAppeared)
{
return null;
}
}
int totalPercentages = _monsterAtLocation.Values.Sum();
int randomNumber = RandomNumberGen.NumberBetween(1, totalPercentages);
int runningTotal = 0;
foreach(KeyValuePair<int,int> monsterKeyValuePair in _monsterAtLocation)
{
runningTotal += monsterKeyValuePair.Value;
if(randomNumber <= runningTotal)
{
return World.MonsterByID(monsterKeyValuePair.Key).NewInstanceOfMonster();
}
}
return World.MonsterByID(_monsterAtLocation.Keys.Last()).NewInstanceOfMonster();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Xml;
using System.Threading.Tasks;
namespace Engine
{
public class Player : LivingCreature
{
private int _gold;
private int _EXP;
private int _strength;
private Location _currentlocation;
public event EventHandler<MessageEventArgs> OnMessage;
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
public int Gold
{
get { return _gold; }
set
{
_gold = value;
OnPropertyChanged("Gold");
}
}
public int EXP
{
get { return _EXP; }
private set
{
_EXP = value;
OnPropertyChanged("EXP");
OnPropertyChanged("Level");
}
}
public int level
{
get { return ((EXP / 100) + 1); }
}
public int Strength
{
get { return _strength; }
set
{
_strength = value;
OnPropertyChanged("Stats");
}
}
public int Endurance { get; set; }
public int Speed { get; set; }
public int Sight { get; set; }
public int Intelligence { get; set; }
public int Charisma {get;set;}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
public Weapon CurrentWeapon { get; set; }
private Monster CurrentMonster { get; set; }
public BindingList<Inventory> Inventory { get; set; }
public BindingList<PlayerQuest> Quest { get; set; }
public Location CurrentLocation
{
get {return _currentlocation; }
set
{
_currentlocation = value;
OnPropertyChanged("CurrentLocation");
}
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
private Player (int hp, int maxhp, int stamina, int gold, int exp, int strength, int endurance, int speed, int sight, int intelligence, int charisma, int ArmorClass) : base (hp, maxhp,stamina)
{
Stamina = stamina;
Gold = gold;
EXP = exp;
Strength = strength;
Endurance = endurance;
Speed = speed;
Sight = sight;
Intelligence = intelligence;
Charisma = charisma;
Inventory = new BindingList<Inventory>();
Quest = new BindingList<PlayerQuest>();
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
public List<Weapon> Weapons
{
get { return Inventory.Where(x => x.Details is Weapon).Select(x => x.Details as Weapon).ToList(); }
}
public List<Healing> Potions
{
get { return Inventory.Where(x => x.Details is Healing).Select(x => x.Details as Healing).ToList(); }
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
private void raiseInventoryChangedEvent(_items item)
{
if(item is Weapon)
{
OnPropertyChanged("Weapons");
}
if(item is Healing)
{
OnPropertyChanged("Potion");
}
}
public void RemoveItemFromInventory(_items itemToRemove, int quantity = 1)
{
Inventory item = Inventory.SingleOrDefault(ii => ii.Details.ID == itemToRemove.ID);
if(item != null)
{
item.Quantity -= quantity;
if(item.Quantity == 0)
{
Inventory.Remove(item);
}
raiseInventoryChangedEvent(itemToRemove);
}
}
public void additemtoinventor(_items itemtoadd, int quantity = 1)
{
Inventory item = Inventory.SingleOrDefault(ii => ii.Details.ID == itemtoadd.ID);
if(item == null)
{
Inventory.Add(new Inventory(itemtoadd, quantity));
}
else
{
item.Quantity+= quantity;
}
raiseInventoryChangedEvent(itemtoadd);
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
public void UsePotion(Healing potion)
{
RaiseMessage("You drink a " + potion.Name);
HealPlayer(potion.AmountToHeal);
RemoveItemFromInventory(potion);
if(CurrentLocation.HasAmonster)
{
LetTheMonsterAttack();
}
}
public void UseWeapon(Weapon weapon)
{
RaiseMessage(CurrentMonster.Name);
int damageToMonster = RandomNumberGen.NumberBetween(weapon.MinDmg, weapon.MaxDmg);
int dice = RandomNumberGen.NumberBetween(1, 20) + (int)(Sight/10);
if(dice == 20)
{
CurrentMonster.HP -= damageToMonster*2;
RaiseMessage("You hit the " + CurrentMonster.Name + " for " + (damageToMonster*2) + ".");
}
else if(dice >= CurrentMonster.Ac)
{
CurrentMonster.HP -= damageToMonster + (int)(Strength/5);
RaiseMessage("You hit the " + CurrentMonster.Name + " for " + damageToMonster + ".");
}
else
{
RaiseMessage("You missed the " + CurrentMonster.Name);
}
if(CurrentMonster.IsDead)
{
LootTheCurrentMonster();
MoveTo(CurrentLocation);
}
else
{
LetTheMonsterAttack();
}
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
private void RaiseMessage (string message, bool addExtraNewLine = false)
{
if(OnMessage != null)
{
OnMessage(this, new MessageEventArgs(message, addExtraNewLine));
}
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
public void MoveTo(Location location)
{
if(Stamina<=0)
{
Stamina = 0;
}
if (!HasRequiredItemToEnter(location))
{
RaiseMessage("You must have a " + location.Itemrequiredtoenter.Name + " to enter this location.");
return;
}
CurrentLocation = location;
if(location.hasAQuest)
{
int quest = 1;
if (PlayerDoesNotHaveThisQuest(location.QuestAvailableHere))
{
GiveQuestToPlayer(World.QuestByID(quest));
}
else
{
if(PlayerHasNotCompleted(World.QuestByID(quest)) && PlayerHasAllQuestCompletionItemFor(World.QuestByID(quest)))
{
GivePlayerQuestRewards(World.QuestByID(quest));
quest++;
if(World.QuestByID(quest) != null)
{
GiveQuestToPlayer(World.QuestByID(quest));
}
}
}
}
SetTheCurrentMonsterForTheCurrentLocation(location);
}
public void moveNorth()
{
if(CurrentMonster != null)
{
LetTheMonsterAttack();
}
if (Stamina <= 0)
{
Stamina = 0;
RaiseMessage("Take a rest you are tired of walking");
}
else if (CurrentLocation.LocationToNorth != null)
{
MoveTo(CurrentLocation.LocationToNorth);
}
}
public void moveEast()
{
if (CurrentMonster != null)
{
LetTheMonsterAttack();
}
if (Stamina <= 0)
{
Stamina = 0;
RaiseMessage("Take a rest you are tired of walking");
}
else if (CurrentLocation.LocationToEast != null)
{
MoveTo(CurrentLocation.LocationToEast);
}
}
public void moveSouth()
{
if (CurrentMonster != null)
{
LetTheMonsterAttack();
}
if (Stamina <= 0)
{
Stamina = 0;
RaiseMessage("Take a rest you are tired of walking");
}
else if (CurrentLocation.LocationToSouth != null)
{
MoveTo(CurrentLocation.LocationToSouth);
}
}
public void moveWest()
{
if (CurrentMonster != null)
{
LetTheMonsterAttack();
}
if (Stamina <= 0)
{
Stamina = 0;
RaiseMessage("Take a rest you are tired of walking");
}
else if (CurrentLocation.LocationToWest != null)
{
MoveTo(CurrentLocation.LocationToWest);
}
}
public void Rest()
{
if (World.LocationByID(World.Location_ID_Camp) == CurrentLocation)
{
HP = MaxHP;
Stamina = 100;
}
else
{
if (MaxHP <= (HP+(int)(MaxHP * .15)))
{
HP = MaxHP;
}
else
{
HP = HP+(int)(MaxHP * .15);
}
if ((Stamina + 40) >= 100)
{
Stamina = 100;
}
else
{
Stamina =+ 40;
}
}
RaiseMessage("You taken a rest and regain health and replenshed stamina");
if(CurrentMonster != null)
{
if(CurrentMonster.HP >= 0)
{
double crit = CurrentMonster.MaxDmg * 1.5;
int damageToPlayer = RandomNumberGen.NumberBetween(10, (int)crit);
RaiseMessage("The " + CurrentMonster.Name + " did " + damageToPlayer + " points of damage.");
HP -= damageToPlayer;
if (HP <= 0)
{
RaiseMessage("The " + CurrentMonster.Name + " killed you.");
Gold = Gold - (int)(0.05 * Gold);
MoveHome();
}
}
}
}
private void MoveHome()
{
MoveTo(World.LocationByID(World.Location_ID_Camp));
HP = MaxHP;
Stamina = 100;
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
private void LootTheCurrentMonster()
{
RaiseMessage("");
RaiseMessage("You defeated the " + CurrentMonster.Name);
RaiseMessage("You receive " + CurrentMonster.RewardEXP + " exp.");
RaiseMessage("You receive " + CurrentMonster.Gold + " gold.");
AddEXP(CurrentMonster.RewardEXP);
Gold += CurrentMonster.Gold;
foreach(Inventory inventory in CurrentMonster.lootItems)
{
additemtoinventor(inventory.Details);
RaiseMessage(string.Format("You loot {0} {1}", inventory.Quantity, inventory.Description));
}
RaiseMessage("");
}
private void HealPlayer(int hpToHeal)
{
HP = Math.Min(HP + hpToHeal, MaxHP);
}
private void LetTheMonsterAttack()
{
int monsterhit = RandomNumberGen.NumberBetween(0, CurrentMonster.Sight+level);
if(monsterhit>=(int)(Speed/2))
{
int damagetoPlayer = RandomNumberGen.NumberBetween(2, CurrentMonster.MaxDmg);
RaiseMessage("The " + CurrentMonster.Name + " did " + damagetoPlayer + " of damage.");
HP -= damagetoPlayer;
if(IsDead)
{
RaiseMessage("You have fainted from the " + CurrentMonster.Name + " attack.");
MoveHome();
Gold = Gold - (int)(0.05*Gold);
}
}
else
{
RaiseMessage("The " + CurrentMonster.Name + " missed.");
}
}
private void AddEXP(int exp)
{
int playerlvlup = 100;
EXP += exp;
if(EXP >=playerlvlup)
{
RaiseMessage("Level Up!");
}
if (EXP >= playerlvlup)
{
if(level == 1)
{
playerlvlup = 300;
}
else if(level == 2)
{
playerlvlup = 900;
}
else if (level == 3)
{
playerlvlup = 1800;
}
else if (level == 4)
{
playerlvlup = 3600;
}
else if (level == 5)
{
}
else if (level == 6)
{
}
else if (level == 7)
{
}
else if (level == 8)
{
}
else if (level == 9)
{
}
else if (level == 10)
{
}
else if (level == 11)
{
}
else if (level == 12)
{
}
else if (level == 13)
{
}
else if (level == 14)
{
}
else if (level == 15)
{
}
}
}
private void GivePlayerQuestRewards(Quest quest)
{
RaiseMessage("");
RaiseMessage("Thank you for " + quest.Description);
RaiseMessage("Take this:");
RaiseMessage(quest.rewardEXP + " EXP");
RaiseMessage(quest.Gold + " gold");
RaiseMessage(quest.rewardItem.Name, true);
AddEXP(quest.rewardEXP);
Gold += quest.Gold;
RemoveQuestCompletuionItems(quest);
additemtoinventor(quest.rewardItem);
MarkQuestAsDone(quest);
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
public static Player CreateDefaultPlayer()
{
Player player = new Player(100, 100, 100, 5, 0, 10, 10, 10, 10, 10, 10, 5);
player.Inventory.Add(new Inventory(World.ItemByID(World.Item_ID_GODSWORD), 1));//GET RID OF
player.Inventory.Add(new Inventory(World.ItemByID(World.Item_ID_Sword), 1));
player.Inventory.Add(new Inventory(World.ItemByID(World.Item_ID_hedgeapple), 1)); // GET RID OF
player.CurrentLocation = World.LocationByID(World.Location_ID_Camp);
return player;
}
public static Player CreatePlayerfromDatabase (int hp, int maxhp, int gold, int exp, int currentlocation)
{
Player player = new Player(hp, maxhp,100, gold, exp,10,10,10,10,10,10,5);
player.MoveTo(World.LocationByID(currentlocation));
return player;
}
public static Player createplayerformxmlString (string xmlPlayerData)
{
try
{
XmlDocument playerdata = new XmlDocument();
playerdata.LoadXml(xmlPlayerData);
int HP = Convert.ToInt32(playerdata.SelectSingleNode("/Player/Stats/HP").InnerText);
int MaxHP = Convert.ToInt32(playerdata.SelectSingleNode("/Player/Stats/MaxHP").InnerText);
int gold = Convert.ToInt32(playerdata.SelectSingleNode("/Player/Stats/Gold").InnerText);
int exp = Convert.ToInt32(playerdata.SelectSingleNode("/Player/Stats/EXP").InnerText);
Player player = new Player(HP, MaxHP,100, gold, exp,10,10,10,10,10,10,5);
int currentLocationID = Convert.ToInt32(playerdata.SelectSingleNode("/Player/Stats/CurrentLocation").InnerText);
player.CurrentLocation = World.LocationByID(currentLocationID);
if(playerdata.SelectSingleNode(".Player/Stats/CurrentWeapon") != null)
{
int currentWeaponID = Convert.ToInt32(playerdata.SelectSingleNode("/Player/Stats/CurrentWeapon").InnerText);
player.CurrentWeapon = (Weapon)World.ItemByID(currentWeaponID);
}
foreach(XmlNode node in playerdata.SelectNodes("/Player/Inventory/Inventory"))
{
int id = Convert.ToInt32(node.Attributes["ID"].Value);
int quantity = Convert.ToInt32(node.Attributes["Quantity"].Value);
for (int i = 0; i < quantity; i++)
{
player.additemtoinventor(World.ItemByID(id));
}
}
foreach(XmlNode node in playerdata.SelectNodes("/Player/PlayerQuest/PlayerQuest"))
{
int id = Convert.ToInt32(node.Attributes["ID"].Value);
bool iscompleted = Convert.ToBoolean(node.Attributes["IsCompleted"].Value);
PlayerQuest playerQuest = new PlayerQuest(World.QuestByID(id));
playerQuest.IsCompleted = iscompleted;
player.Quest.Add(playerQuest);
}
return player;
}
catch
{
return CreateDefaultPlayer();
}
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
public bool HasRequiredItemToEnter(Location location)
{
if(location.Itemrequiredtoenter == null)
{
return true;
}
return Inventory.Any(ii => ii.Details.ID == location.Itemrequiredtoenter.ID);
}
public bool hasallquestcompleted(Quest quest)
{
foreach(QuestCompletedItem qci in quest.QuestCompletedItem)
{
if(!Inventory.Any(ii=>ii.Details.ID==qci.Details.ID &&ii.Quantity>=qci.Quanity))
{
return false;
}
}
return true;
}
private bool HasRequiredItemToEnterThisLcoation(Location location)
{
if(location.NoReqiredItemToEnter)
{
return true;
}
return Inventory.Any(ii => ii.Details.ID == location.Itemrequiredtoenter.ID);
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
public void MarkQuestAsDone(Quest quest)
{
PlayerQuest playerQuest = Quest.SingleOrDefault(pq => pq.Details.ID == quest.ID);
if(playerQuest != null)
{
playerQuest.IsCompleted = true;
}
}
private void GiveQuestToPlayer(Quest quest)
{
RaiseMessage("You receive the " + quest.Name + " quest.");
RaiseMessage(quest.Description);
RaiseMessage("To complete it, return with:");
foreach(QuestCompletedItem qci in quest.QuestCompletedItem)
{
RaiseMessage(string.Format("{0} {1}", qci.Quanity, qci.Quanity == 1 ? qci.Details.Name : qci.Details.NamePlural));
}
RaiseMessage("");
Quest.Add(new PlayerQuest(quest));
}
private bool PlayerHasAllQuestCompletionItemFor(Quest quest)
{
foreach(QuestCompletedItem qci in quest.QuestCompletedItem)
{
if(!Inventory.Any(ii => ii.Details.ID == qci.Details.ID && ii.Quantity >= qci.Quanity))
{
return false;
}
}
return true;
}
private void RemoveQuestCompletuionItems(Quest quest)
{
foreach(QuestCompletedItem qci in quest.QuestCompletedItem)
{
Inventory item = Inventory.SingleOrDefault(ii => ii.Details.ID == qci.Details.ID);
if(item != null)
{
RemoveItemFromInventory(item.Details, qci.Quanity);
}
}
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
private void SetTheCurrentMonsterForTheCurrentLocation(Location location)
{
CurrentMonster = location.NewInstanceOfMonsterLivingHere();
if(CurrentMonster != null)
{
RaiseMessage("You see a " + CurrentMonster.Name);
}
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
private bool PlayerDoesNotHaveTheRequiredItemToEnter (Location location)
{
return !HasRequiredItemToEnter(location);
}
private bool PlayerDoesNotHaveThisQuest (Quest quest)
{
return Quest.All(pq => pq.Details.ID != quest.ID);
}
private bool PlayerHasNotCompleted (Quest quest)
{
return Quest.Any(pq => pq.Details.ID == quest.ID && !pq.IsCompleted);
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
public string Toxmlstring()
{
XmlDocument playerData = new XmlDocument();
XmlNode player = playerData.CreateElement("Player");
playerData.AppendChild(player);
XmlNode stats = playerData.CreateElement("Stats");
player.AppendChild(stats);
XmlNode HP = playerData.CreateElement("HP");
HP.AppendChild(playerData.CreateTextNode(this.HP.ToString()));
stats.AppendChild(HP);
XmlNode maxHP = playerData.CreateElement("MaxHP");
maxHP.AppendChild(playerData.CreateTextNode(this.MaxHP.ToString()));
stats.AppendChild(maxHP);
XmlNode gold = playerData.CreateElement("Gold");
gold.AppendChild(playerData.CreateTextNode(this.Gold.ToString()));
stats.AppendChild(gold);
XmlNode exp = playerData.CreateElement("EXP");
exp.AppendChild(playerData.CreateTextNode(this.EXP.ToString()));
stats.AppendChild(exp);
XmlNode currentLocation = playerData.CreateElement("CurrentLocation");
currentLocation.AppendChild(playerData.CreateTextNode(this.CurrentLocation.ID.ToString()));
stats.AppendChild(currentLocation);
if(CurrentWeapon != null)
{
XmlNode currentWeapon = playerData.CreateElement("CurrentWeapon");
currentWeapon.AppendChild(playerData.CreateTextNode(this.CurrentWeapon.ID.ToString()));
stats.AppendChild(currentWeapon);
}
XmlNode inventoryItems = playerData.CreateElement("InventoryItem");
player.AppendChild(inventoryItems);
foreach(Inventory item in this.Inventory)
{
XmlNode inventoryItem = playerData.CreateElement("InventoryItem");
XmlAttribute idattribute = playerData.CreateAttribute("ID");
idattribute.Value = item.Details.ID.ToString();
inventoryItem.Attributes.Append(idattribute);
XmlAttribute quantityAttribute = playerData.CreateAttribute("Quantity");
quantityAttribute.Value = item.Quantity.ToString();
inventoryItem.Attributes.Append(quantityAttribute);
inventoryItem.AppendChild(inventoryItem);
}
XmlNode playerQuest = playerData.CreateElement("PlayerQuests");
player.AppendChild(playerQuest);
foreach(PlayerQuest quest in this.Quest)
{
XmlNode playerquest = playerData.CreateElement("PlayerQuest");
XmlAttribute idAttribute = playerData.CreateAttribute("ID");
idAttribute.Value = quest.Details.ID.ToString();
playerquest.Attributes.Append(idAttribute);
XmlAttribute iscompletedAttribute = playerData.CreateAttribute("Iscompleted");
iscompletedAttribute.Value = quest.IsCompleted.ToString();
playerquest.Attributes.Append(iscompletedAttribute);
playerquest.AppendChild(playerquest);
}
return playerData.InnerXml;
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Engine
{
public static class World
{
public static readonly List<_items> _items = new List<_items>();
public static readonly List<Monster> _monsters = new List<Monster>();
public static readonly List<Quest> _quests = new List<Quest>();
public static readonly List<Location>_locations = new List<Location>();
public const int UNSELLABLE_ITEM_PRICE = -1;
public const int Item_ID_Sword = 1; //130gp
public const int Item_ID_Bow = 2; //110gp
public const int Item_ID_Staff = 3; //120gp
public const int Item_ID_hedgeapple = 4; //6gp
public const int Item_ID_arcobot_Fang = 5; //4gp
public const int Item_ID_Chunks_of_leather = 6; //6gp
public const int Item_ID_GODSWORD = 9999; //beta weapon
public const int Monster_ID_NOTHING = -1;
public const int Monster_ID_Arcobot = 1;
public const int Monster_ID_Bandit = 2;
public const int Monster_ID_Man_Eater = 3;
public const int Monster_ID_Ent = 4;
public const int Monster_ID_2BearsHighFiving = 5;
public const int Quest_ID_Clear_Kill_5_arcobot = 1;
public const int Quest_ID_Clear_retreive_5_Chucks_of_lether = 2;
public const int Location_ID_Camp = 1;
public const int Location_ID_Forst = 2;
public const int Location_ID_Jungle = 3;
public const int Location_ID_Mountain = 4;
public const int Location_ID_Pasture = 5;
public const int Location_ID_Cave = 6;
public const int Location_ID_DeepCave = 7;
public const int Location_ID_Water = 8;
public const int Location_ID_Beach = 9;
public const int Location_ID_Town = 10;
public const int Location_ID_LostsSHOP = 010;
public const int Location_ID_Bandit_Encampment = 11;
static World()
{
PopulateItems();
PopulateMonsters();
PopulateQuest();
PopulateLocation();
}
private static void PopulateItems()
{
_items.Add(new Weapon(Item_ID_Sword, "Damaged Captain's Sword", "Damaged Captain's Swords", 5, 10,130));
_items.Add(new Weapon(Item_ID_Bow, "Old Bow", "Old Bows", 3, 12,110));
_items.Add(new Weapon(Item_ID_Staff, "Rotten staff", "Rotten staffs", 4, 9,120));
_items.Add(new Weapon(Item_ID_GODSWORD, "GOD SWORD", "GOD SWORDS", 9998, 9999,-1));
_items.Add(new Healing(Item_ID_hedgeapple, "Hedge apple", "Hedge apples",9999,6)); //CHANGE LATER ONLY FOR BETA IS 9999
_items.Add(new _items(Item_ID_arcobot_Fang, "Arcobot's Fang", "Arcobot's Fangs",4));
_items.Add(new _items(Item_ID_Chunks_of_leather, "Chunk of Leather", "chunks of leather",6));
}
private static void PopulateMonsters()
{
Monster AcroBot = new Monster(Monster_ID_Arcobot,"Arcobot", 12,5,2,50,50,999,4,8);
AcroBot.LootTable.Add(new LootItem(ItemByID(Item_ID_arcobot_Fang),40,false));
Monster Bandit = new Monster(Monster_ID_Bandit, "Bandit", 21, 12, 7, 75, 75,999,6,9);
Bandit.LootTable.Add(new LootItem(ItemByID(Item_ID_Chunks_of_leather), 40, false));
Monster ManEater = new Monster(Monster_ID_Man_Eater, "Man Eater", 37, 27, 4, 125, 125, 999,12,4);
ManEater.LootTable.Add(new LootItem(ItemByID(Item_ID_hedgeapple), 100, true));
Monster Ent = new Monster(Monster_ID_Ent, "Ent", 42, 110, 2, 200, 200, 999,15,12);
Monster bearshighfiving = new Monster(Monster_ID_2BearsHighFiving, "Bear", 32, 20, 14, 100, 100, 999,1,8);
_monsters.Add(AcroBot);
_monsters.Add(Bandit);
_monsters.Add(ManEater);
_monsters.Add(Ent);
_monsters.Add(bearshighfiving);
}
private static void PopulateQuest()
{
Quest KillArcoBots = new Quest(Quest_ID_Clear_Kill_5_arcobot, "Bot Killer", "Go to the forest and kill 5 arcobots and bring back 3 iron fangs.",40,30);
KillArcoBots.QuestCompletedItem.Add(new QuestCompletedItem(ItemByID(Item_ID_arcobot_Fang), 3));
KillArcoBots.rewardItem = ItemByID(Item_ID_hedgeapple);
Quest Protector = new Quest(Quest_ID_Clear_retreive_5_Chucks_of_lether, "They protect, They Attack, and they are...", "kill off those bandits and retrieve 5 chuncks of leather for us.",70,64);
Protector.QuestCompletedItem.Add(new QuestCompletedItem(ItemByID(Item_ID_Chunks_of_leather), 5));
Protector.rewardItem = ItemByID(Item_ID_hedgeapple);//REPLACE rewards with real items later
_quests.Add(KillArcoBots);
_quests.Add(Protector);
}
private static void PopulateLocation()
{ //odds y<0 evens y>0
Location Camp = new Location(Location_ID_Camp, "Camp", "The makeshift place you call home... cozy");
//
Location Forest = new Location(Location_ID_Forst, "Forest", "Tall trees stand in your way, These trees are so big a weagon can fit though one.");
Forest.NewInstanceOfMonsterLivingHere();
Forest.AddMonster(Monster_ID_Bandit, 20);
Forest.AddMonster(Monster_ID_Arcobot, 20);
Forest.MonsterAppearanceChance = 50;
Location f1 = new Location(Location_ID_Forst, "Forest", "Tall trees stand in your way, These trees are so big a weagon can fit though one.");//0,1
Location f2 = new Location(Location_ID_Forst, "Forest", "Tall trees stand in your way, These trees are so big a weagon can fit though one.");
Location f3 = new Location(Location_ID_Forst, "Forest", "Tall trees stand in your way, These trees are so big a weagon can fit though one.");
Location f4 = new Location(Location_ID_Forst, "Forest", "Tall trees stand in your way, These trees are so big a weagon can fit though one.");
Location f5 = new Location(Location_ID_Forst, "Forest", "Tall trees stand in your way, These trees are so big a weagon can fit though one.");
Location f6 = new Location(Location_ID_Forst, "Forest", "Tall trees stand in your way, These trees are so big a weagon can fit though one.");
Location f7 = new Location(Location_ID_Forst, "Forest", "Tall trees stand in your way, These trees are so big a weagon can fit though one.");
Location f8 = new Location(Location_ID_Forst, "Forest", "Tall trees stand in your way, These trees are so big a weagon can fit though one.");
Location f10 = new Location(Location_ID_Forst, "Forest", "Tall trees stand in your way, These trees are so big a weagon can fit though one.");
Location f10a = new Location(Location_ID_Forst, "Forest", "Tall trees stand in your way, These trees are so big a weagon can fit though one.");
Location f6a = new Location(Location_ID_Forst, "Forest", "Tall trees stand in your way, These trees are so big a weagon can fit though one.");
Location f01 = new Location(Location_ID_Forst, "Forest", "Tall trees stand in your way, These trees are so big a weagon can fit though one.");
Location f02 = new Location(Location_ID_Forst, "Forest", "Tall trees stand in your way, These trees are so big a weagon can fit though one.");
Location f03 = new Location(Location_ID_Forst, "Forest", "Tall trees stand in your way, These trees are so big a weagon can fit though one.");
//
Location Jungle = new Location(Location_ID_Jungle, "Jungle", "Vines hang from the tree tops, barely little light come from the canopy; don't travel at night here.");
//
Location Mountain = new Location(Location_ID_Mountain, "Mountain", "Far pass the town and jungle is mountains it going to take a while to get their; and it looks cold bring a coat.");
//
Location Town = new Location(Location_ID_Town, "Lost Town", "Before the Jungle stand a small hut town, peaceful and calm without bandits atleast.");
Location t8a = new Location(Location_ID_Town, "Lost Town", "Before the Jungle stand a small hut town, peaceful and calm without bandits atleast.");
Location t8b = new Location(Location_ID_Town, "Lost Town", "Before the Jungle stand a small hut town, peaceful and calm without bandits atleast.");
Location t8c = new Location(Location_ID_Town, "Lost Town", "Before the Jungle stand a small hut town, peaceful and calm without bandits atleast.");
Location Jail = new Location(Location_ID_Town, "Jail", "Before the Jungle stand a small hut town, peaceful and calm without bandits atleast.");
Location GuildHall = new Location(Location_ID_Town, "Guild Hall", "Before the Jungle stand a small hut town, peaceful and calm without bandits atleast.");
GuildHall.QuestAvailableHere = QuestByID(Quest_ID_Clear_retreive_5_Chucks_of_lether);
GuildHall.QuestAvailableHere = QuestByID(Quest_ID_Clear_Kill_5_arcobot);
Location Med = new Location(Location_ID_Town, "Clinic", "Before the Jungle stand a small hut town, peaceful and calm without bandits atleast.");
Location Shop = new Location(Location_ID_LostsSHOP, "Shop", "Welecome to the Shop"); // Change later
Vendortron9000 Vendy = new Vendortron9000("Vendy");
Vendy.Additemtoinventory(ItemByID(Item_ID_Chunks_of_leather), 999);
Vendy.Additemtoinventory(ItemByID(Item_ID_hedgeapple), 999);
Vendy.Additemtoinventory(ItemByID(Item_ID_Sword), 99);
Vendy.Additemtoinventory(ItemByID(Item_ID_Staff), 99);
Vendy.Additemtoinventory(ItemByID(Item_ID_arcobot_Fang), 99);
Vendy.Additemtoinventory(ItemByID(Item_ID_Bow), 99);
Shop.Vending = Vendy;
Location Bar = new Location(Location_ID_Town, "Bar", "Before the Jungle stand a small hut town, peaceful and calm without bandits atleast.");
//
Location BanditEncampment = new Location(Location_ID_Bandit_Encampment, "Bandit Encampment", "Bandits stand gaurd, The wall that surrounds them makes it only one way in one way out.");
//
Location Pasture = new Location(Location_ID_Pasture, "Pasture", "The open green field stands before you.");
Location p1 = new Location(Location_ID_Pasture, "Pasture", "The open green field stands before you.");
Location p2 = new Location(Location_ID_Pasture, "Pasture", "The open green field stands before you.");
//
Location Cave = new Location(Location_ID_Cave, "Cave Entrance", "Their seems to be a cave wonders of what could be in the bellows of it.");
//
Location DeepCave = new Location(Location_ID_DeepCave, "Deep Cave", "The further you go the darker it gets.");
//
Location Beach = new Location(Location_ID_Beach, "Beach", "Pearly white sand on a sunny day, to bad theirs creatures here.");
//
Location Water = new Location(Location_ID_Water, "Water", "The water is cool and deep, if you enter it might just rip you ashreds.");
//
Camp.LocationToNorth = Pasture;
Pasture.LocationToEast = p1;
Pasture.LocationToWest = p2; //OG LINE
Pasture.LocationToNorth = Forest;
Pasture.LocationToSouth = Camp;
p2.LocationToEast = Pasture; //0,1 TOP ROW
p2.LocationToNorth = f2;
p1.LocationToWest = Pasture;
p1.LocationToNorth = f1; //0,-1 BOTTOM ROW
//FOREST AREA
Forest.LocationToNorth = f01; //1,0 OG LINE
Forest.LocationToEast = f1;
Forest.LocationToWest = f2;
Forest.LocationToSouth = Pasture;
f2.LocationToEast = Forest;//1,1 // top
f2.LocationToNorth = f4;
f2.LocationToSouth = p2;
f1.LocationToNorth = f3;//1,-1
f1.LocationToSouth = p1;
f1.LocationToWest = Forest;
f01.LocationToNorth = f02;//2,0 OG LINE
f01.LocationToEast = f3;
f01.LocationToSouth = Forest;
f01.LocationToWest = f4;
f4.LocationToNorth = f6;//2,1
f4.LocationToEast = f01;
f4.LocationToSouth = f2;
f3.LocationToNorth = f5;//2.-1
f3.LocationToWest = f01;
f3.LocationToSouth = f1;
f3.LocationToEast = Cave;
f02.LocationToNorth = f03; //3,0
f02.LocationToEast = f5;
f02.LocationToWest = f6;
f02.LocationToSouth = f01;
f6.LocationToNorth = f8; //3,1
f6.LocationToWest = f6a;
f6.LocationToSouth = f4;
f6.LocationToEast = f02;
f5.LocationToNorth = f7; //3,-1
f5.LocationToSouth = f3;
f5.LocationToWest = f02;
f6a.LocationToNorth = Town;//3,2
f6a.LocationToEast = f6;
f03.LocationToEast = f7; //4,0
f03.LocationToSouth = f02;
f03.LocationToWest = f8;
f7.LocationToWest = f03; //4,-1
f7.LocationToSouth = f5;
f8.LocationToWest = Town; //4,1
f8.LocationToEast = f03;
f8.LocationToNorth = f10;
f8.LocationToSouth = f6;
f10.LocationToSouth = f8;//5,1
f10.LocationToWest = f10a;
f10a.LocationToEast = f10;//5,2
f10a.LocationToSouth = Town;
//Town
Town.LocationToSouth = f6a; //4,2 OR ENTRANCE OF TOWN
Town.LocationToNorth = f10a;
Town.LocationToEast = f8;
Town.LocationToWest = t8a;
t8a.LocationToWest = t8b;//4,3
t8a.LocationToEast = Town;
t8a.LocationToSouth = Jail; // Jailhouse at 3,3
t8b.LocationToEast = t8a; // 4,4
t8b.LocationToNorth = Bar; //Bar
t8b.LocationToSouth = GuildHall; //Guild Hall
t8b.LocationToWest = t8c;
t8c.LocationToEast = t8b;//4,5
t8c.LocationToSouth = Med;//Med
t8c.LocationToNorth = Shop;//Shop
Med.LocationToNorth = t8c; //Med 3,5
Shop.LocationToSouth = t8c; //Shop 5,5
GuildHall.LocationToNorth = t8b; //Guild Hall 3,4
Bar.LocationToSouth = t8b; //Bar 5,4
Jail.LocationToNorth = t8a; //Jail 3,3
//Cave
Cave.LocationToWest = f3;
//BREAKER
_locations.Add(Camp);
_locations.Add(Town);
_locations.Add(Forest);
_locations.Add(Cave);
_locations.Add(Pasture);
_locations.Add(Shop);
}
public static _items ItemByID(int id)
{
return _items.SingleOrDefault(x => x.ID == id);
}
public static Monster MonsterByID(int id)
{
return _monsters.SingleOrDefault(x => x.ID == id);
}
public static Quest QuestByID (int id)
{
return _quests.SingleOrDefault(x => x.ID == id);
}
public static Location LocationByID(int id)
{
return _locations.SingleOrDefault(x => x.ID == id);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment