Beispiel #1
0
            public async Task Equip(Slot slot, [ItemTypeSlot, InInventory] Item item)
            {
                Player player = GetPlayer();

                if (!player.equipped.ContainsKey(slot))
                {
                    player.equipped.Add(slot, null);
                }

                ItemCount itemCount = player.items.FirstOrDefault(test => test.item == item);

                string message = "";

                ItemCount equipped = player.equipped[slot];

                if (equipped != null && equipped.item != null)
                {
                    message += $"You unequipped your {equipped.item.name}.\n";
                    player.ReturnEquipment(equipped);
                    player.equipped[slot] = null;
                }

                message += $"You have equipped {itemCount.item.name}.";

                player.equipped[slot] = player.TakeEquipment(itemCount);

                await ReplyAsync(message);
            }
Beispiel #2
0
            public async Task GiveAllItems()
            {
                Player player = GetPlayer();

                foreach (Item item in ChatCraft.Instance.State.items)
                {
                    if (item.itemType == ItemType.Armor || item.itemType == ItemType.Tool)
                    {
                        player.items.Add(new ItemCount(item, item.durability));
                    }
                    else
                    {
                        ItemCount existing = player.items.FirstOrDefault(count => count.item == item);

                        if (existing != null)
                        {
                            existing.count++;
                        }
                        else
                        {
                            player.items.Add(new ItemCount(item, 10));
                        }
                    }
                }

                await ReplyAsync("Well aren't you a lucky bugger.");
            }
Beispiel #3
0
        public async Task Give(IUser user, int count, [InInventory] Item item)
        {
            Player player = GetPlayer();

            ItemCount itemCount = player.items.FirstOrDefault(test => test.item == item);

            if (count > itemCount.count)
            {
                await ReplyAsync($"You don't have {count} {itemCount.item.name}. You only have {itemCount.count}.");
            }
            else
            {
                Player other = GetPlayer(user);

                if (itemCount.item.itemType == ItemType.Armor ||
                    itemCount.item.itemType == ItemType.Tool)
                {
                    other.items.Add(itemCount);
                    player.items.Remove(itemCount);
                }
                else
                {
                    other.AddItem(itemCount.item, count);
                    player.ConsumeItem(itemCount.item, count);
                }

                await ReplyAsync($"You gave {user.Username} {count} {itemCount.item.name}.");
            }
        }
Beispiel #4
0
		public int ItemCount(Item item)
		{
			switch (item.itemType)
			{
				case ItemType.General:
				case ItemType.Consumable:
				case ItemType.Pendant:
				case ItemType.Ring:
				case ItemType.StackingTool:

				ItemCount itemCount = items.FirstOrDefault(test => test.item == item);

				if (itemCount == null)
				{
					return 0;
				}

				return itemCount.count;

				case ItemType.Tool:
				case ItemType.Armor:

				return items.Count(test => test.item == item);
			}

			return 0;
		}
Beispiel #5
0
		public void AddItem(Item item, int count = 1)
		{
			switch (item.itemType)
			{
				case ItemType.General:
				case ItemType.Consumable:
				case ItemType.Pendant:
				case ItemType.Ring:
				case ItemType.StackingTool:
				ItemCount itemCount = items.FirstOrDefault(test => test.item == item);

				if (itemCount == null)
				{
					itemCount = new ItemCount(item, 0);
					items.Add(itemCount);
				}

				itemCount.count += count;
				break;

				case ItemType.Tool:
				case ItemType.Armor:
				for (int i = 0; i < count; i++)
				{
					itemCount = new ItemCount(item, item.durability);
					items.Add(itemCount);
				}
				break;
			}
		}
Beispiel #6
0
		public void ReturnEquipment(ItemCount equipment)
		{
			switch (equipment.item.itemType)
			{
				case ItemType.General:
				case ItemType.Consumable:
				case ItemType.Pendant:
				case ItemType.Ring:
				case ItemType.StackingTool:

				ItemCount itemCount = items.FirstOrDefault(test => test.item == equipment.item);

				if (itemCount == null)
				{
					itemCount = new ItemCount(equipment.item, 0);
					items.Add(itemCount);
				}

				itemCount.count += equipment.count;
				break;

				case ItemType.Tool:
				case ItemType.Armor:

				items.Add(equipment);
				break;
			}
		}
Beispiel #7
0
		public ItemCount TakeEquipment(ItemCount itemCount)
		{
			switch (itemCount.item.itemType)
			{
				case ItemType.General:
				case ItemType.Consumable:
				case ItemType.Pendant:
				case ItemType.Ring:
				case ItemType.StackingTool:

				itemCount.count--;
				
				if (itemCount.count == 0)
				{
					items.Remove(itemCount);
				}

				return new ItemCount(itemCount.item, 1);

				case ItemType.Tool:
				case ItemType.Armor:

				items.Remove(itemCount);
				return itemCount;
			}

			return null;
		}
Beispiel #8
0
            public async Task Unequip(Slot slot)
            {
                Player player = GetPlayer();

                if (!player.equipped.ContainsKey(slot))
                {
                    player.equipped.Add(slot, null);
                }

                ItemCount equipped = player.equipped[slot];

                if (equipped == null)
                {
                    await ReplyAsync($"You have no {slot.names[0]} equipped.");
                }
                else
                {
                    await ReplyAsync($"You have unequipped {equipped.item.name}.");

                    player.ReturnEquipment(equipped);
                    player.equipped[slot] = null;
                }
            }
Beispiel #9
0
		public void ConsumeItem(Item item, int count = 1)
		{
			switch (item.itemType)
			{
				case ItemType.General:
				case ItemType.Consumable:
				case ItemType.Pendant:
				case ItemType.Ring:
				ItemCount itemCount = items.FirstOrDefault(test => test.item == item);

				if (itemCount != null)
				{
					itemCount.count = Math.Max(0, itemCount.count - count);

					if (itemCount.count == 0)
					{
						items.Remove(itemCount);
					}
				}

				break;

				case ItemType.Tool:
				case ItemType.Armor:
				for (int i = 0; i < count; i++)
				{
					itemCount = items.FirstOrDefault(test => test.item == item);

					if (itemCount != null)
					{
						items.Remove(itemCount);
					}
				}
				break;
			}
		}
Beispiel #10
0
        public static string Explore(string name, Location location, float luck, Predicate <Location> isKnown, out Encounter bestEncounter, out Location bestLocation, out ItemCount bestItem)
        {
            Random random = new Random();

            double bestEncounterWeight = 1f;

            bestEncounter = null;

            location.exploreSet?.encounterSet?.GetBest(random, ref bestEncounter, ref bestEncounterWeight);

            double bestLocationWeight = bestEncounterWeight;

            bestLocation = null;

            foreach (Connection connection in location.connections)
            {
                bool isA = connection.locationA == location;

                Location other  = isA ? connection.locationB : connection.locationA;
                float    chance = isA ? connection.chanceToFindB : connection.chanceToFindA;

                if (!isKnown(other))
                {
                    double value = random.NextDouble() / chance;

                    if (value < bestLocationWeight)
                    {
                        bestLocation       = other;
                        bestLocationWeight = value;
                    }
                }
            }

            double          bestItemWeight      = bestEncounterWeight;
            ItemWeightCount bestItemWeightCount = null;

            bestItem = null;

            location.exploreSet?.itemSet?.GetBest(random, ref bestItemWeightCount, ref bestEncounterWeight);

            if (bestItemWeightCount != null)
            {
                bestItem = new ItemCount(bestItemWeightCount.item, random.Next(bestItemWeightCount.minimum, bestItemWeightCount.maximum + 1));
            }

            string message = $"{name} explore {location.name}.\n";

            if (location.descriptions.Count > 0)
            {
                message += location.descriptions[random.Next(location.descriptions.Count)] + "\n";
            }

            message += "\n";

            if (bestItem != null)
            {
                bestEncounter = null;
                bestLocation  = null;

                if (bestItem.count > 1)
                {
                    message += $"You found {bestItem.count} {bestItem.item.name}s.";
                }
                else
                {
                    message += $"You found a {bestItem.item.name}.";
                }
            }
            else if (bestLocation != null)
            {
                bestEncounter = null;

                message += $"{name} discovered {bestLocation.name}.";
            }
            else if (bestEncounter != null)
            {
                message += $"{name} encountered a {bestEncounter.name}.\n";
                message += $"{bestEncounter.possibleDescriptions[random.Next(bestEncounter.possibleDescriptions.Count)]}\n";
                message += $"";
            }
            else
            {
                message += $"{name} didn't find anything!";
            }

            return(message);
        }
                public async Task AttackUser([Hand] Slot hand, [InCombatWith, Enemy] Unit target)
                {
                    Player player = GetPlayer();

                    bool isAttacked;
                    bool isLeft = hand.names.Contains("lh");

                    if (isLeft)
                    {
                        isAttacked = player.combatState.isLeftHandAttacked;
                        player.combatState.isLeftHandAttacked = true;
                    }
                    else
                    {
                        isAttacked = player.combatState.isRightHandAttacked;
                        player.combatState.isRightHandAttacked = true;
                    }

                    if (isAttacked)
                    {
                        await ReplyAsync("You have already attacked with that hand.");

                        return;
                    }

                    ItemCount held = player.equipped[hand];

                    int damage = 1;

                    if (held == null)
                    {
                        await ReplyAsync($"{player.name} punched {target.name} dealing {damage} damage.");
                    }
                    else
                    {
                        Item item = held.item;

                        Unit.StatGroup damageStat = player.GetStat("Damage");
                        damage = isLeft ? damageStat.LeftTotal : damageStat.RightTotal;

                        await ReplyAsync($"{player.name} attacked {target.name} with {item.name} dealing {damage} damage.");
                    }

                    Unit.StatGroup healthStat = target.GetStat("Health");
                    healthStat.Modify(-damage);

                    if (healthStat.Total > 0)
                    {
                        await ReplyAsync($"{target.name} is on {healthStat.Total} health.");
                    }
                    else
                    {
                        await ReplyAsync($"{target.name} was killed.");

                        CombatInstance combat = target.combatState.instance;

                        combat.Killed(target);

                        if (combat.isOver)
                        {
                            await ReplyAsync("The fight is over.");
                        }
                    }
                }