Beispiel #1
0
        public void PopulateDataToList <T>(DataTable dataTable, List <T> list)
        {
            dataTable.AcceptChanges();

            foreach (DataRow dr in dataTable.Rows)
            {
                var          tt           = Activator.CreateInstance <T>();
                WearableItem wearableItem = tt as WearableItem;

                wearableItem.Name        = (dr["Name"] + "").Replace(',', ';');
                wearableItem.Description = (dr["Description"] + "").Replace(',', ';');


                int a = 0;
                int b = 0;
                int c = 0;

                int.TryParse((dr["Strength"] + ""), out a);
                int.TryParse((dr["Inteligence"] + ""), out b);
                int.TryParse((dr["Defence"] + ""), out c);

                wearableItem.Power = new Ability()
                {
                    Strength = a, Inteligence = b, Defence = c
                };

                list.Add(tt);
            }
        }
Beispiel #2
0
 public static void SaveWearable(WearableItem item, string filePath)
 {
     try
     {
         File.WriteAllText(filePath + item.Name + ".csv", $"{item.Name},{item.Description},{item.Power.Strength},{item.Power.Inteligence},{item.Power.Defence}");
     }
     catch (Exception)
     {
     }
 }
 public static WearableItem Clone(WearableItem ToClone)
 {
     return(new WearableItem()
     {
         Name = ToClone.Name,
         Description = ToClone.Description,
         Power = new Ability()
         {
             Defence = ToClone.Power.Defence,
             Strength = ToClone.Power.Strength,
             Inteligence = ToClone.Power.Inteligence
         }
     });
 }
Beispiel #4
0
        public static void LoadWearable(string filePath, IList list, WearableItem item)
        {
            string fileData = File.ReadAllText(filePath);

            string[] splitData = fileData.Split(',');

            if (splitData.Length == 5)
            {
                item.Name        = splitData[0];
                item.Description = splitData[1];
                item.Power       = new Ability()
                {
                    Strength = int.Parse(splitData[2]), Inteligence = int.Parse(splitData[3]), Defence = int.Parse(splitData[4])
                };
                list.Add(item);
            }
        }
Beispiel #5
0
        public void AddRowToEquipt(DataTable dt, WearableItem item)
        {
            if (item == null)
            {
                return;
            }
            DataRow dr = dt.NewRow();

            dr["Name"]        = item.Name;
            dr["Description"] = item.Description;

            dr["Strength"]    = item.Power.Strength;
            dr["Inteligence"] = item.Power.Inteligence;
            dr["Defence"]     = item.Power.Defence;
            dr["Item"]        = item;

            if (item is HeadItem)
            {
                dr["Location"] = "Head";
            }
            else if (item is ChestItem)
            {
                dr["Location"] = "Chest";
            }
            else if (item is LegsItem)
            {
                dr["Location"] = "Legs";
            }
            else if (item is FeetItem)
            {
                dr["Location"] = "Feet";
            }
            else
            {
                dr["Location"] = "Hands";
            }

            dt.Rows.Add(dr);
        }
Beispiel #6
0
        public void ProcessBuyOrMakeItem(IList Items, string Caption)
        {
            bool inList = true;

            string input;

            do
            {
                List <Tuple <string, string, Action> > Commands1 = new List <Tuple <string, string, Action> >();

                foreach (var item in Items)
                {
                    WearableItem wearableItem = null;
                    if (item is WearableItem)
                    {
                        wearableItem = (WearableItem)item;
                    }
                    if (wearableItem != null)
                    {
                        var price = item is ToolItem ? (item as ToolItem).Price : (wearableItem.Power.Strength + 1) * (wearableItem.Power.Inteligence + 1) * (wearableItem.Power.Defence + 1) *
                                    (ActiveBuilding.Type == BuildingType.Blacksmith ? ActiveBuilding.Owner.Smithing.Value : 1);

                        Commands1.Add(new Tuple <string, string, Action>($"{Commands1.Count}: {wearableItem.Name}, price: { GetOrenLabel(price) }", $"{wearableItem.Name},{Commands1.Count}", () =>
                        {
                            if (Question($"{ActiveBuilding.Owner.Name}: Are you sure you would like to buy a {wearableItem.Name} for { GetOrenLabel(price) }?", "yes", "no") == "yes")
                            {
                                if (MainCharacter.Orens >= price)
                                {
                                    MainCharacter.Orens -= price;

                                    if (ActiveBuilding.Type == BuildingType.Blacksmith)
                                    {
                                        // we are making the item

                                        WearableItem witem = Activator.CreateInstance(wearableItem.GetType()) as WearableItem;
                                        var multiplier     = (1.0f + (ActiveBuilding.Owner.Smithing.Value / 100.0f));
                                        witem.Description  = wearableItem.Description;
                                        witem.Name         = wearableItem.Name;
                                        witem.Power        = new Ability()
                                        {
                                            Strength = (int)(wearableItem.Power.Strength * multiplier), Defence = (int)(wearableItem.Power.Defence * multiplier), Inteligence = (int)(wearableItem.Power.Inteligence * multiplier)
                                        };

                                        MainCharacter.Inventory.Items.Add(witem);
                                    }
                                    else
                                    {
                                        MainCharacter.Inventory.Items.Add(wearableItem);
                                    }

                                    WriteLineColor($"You have know spent {GetOrenLabel(price)}.", ConsoleColor.Yellow, ConsoleColor.Black);
                                    WriteLineColor($"You now have {GetOrenLabel(MainCharacter.Orens)}", ConsoleColor.Yellow, ConsoleColor.Black);

                                    UpdateStats(MainCharacter);
                                }
                                else
                                {
                                    WriteLineColor($"You do not have enough oren's, Please come back when you have enough.", ConsoleColor.Yellow, ConsoleColor.Black);
                                }
                                if (Question($"{ActiveBuilding.Owner.Name}: Was that all you needed {MainCharacter.Name}?", "yes", "no") == "yes")
                                {
                                    inList = false;
                                }
                            }
                        }));
                    }
                }

                Commands1.Add(new Tuple <string, string, Action>($"{Commands1.Count}: Nothing, Sorry", $"{Commands1.Count}nothing,sorry", () =>
                {
                    inList = false;
                }));

                List <string> Options1 = new List <string>();
                var           Builder1 = new StringBuilder(ActiveBuilding.Owner.Name + $": Which {Caption} would you like me to buy?\r\n");

                foreach (var item in Commands1)
                {
                    Options1.Add(item.Item2);
                    Builder1.AppendLine(item.Item1);
                }

                input = Question(Builder1.ToString(), Options1.ToArray());


                for (int i = 0; i < Options1.Count; i++)
                {
                    if (input == Commands1[i].Item2.ToLower())
                    {
                        Commands1[i].Item3();
                        break;
                    }
                }
            } while (inList);
        }