165 lines
5.0 KiB
C#
165 lines
5.0 KiB
C#
using Newtonsoft.Json.Linq;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Assets.Scripts
|
|
{
|
|
public class CollectQuest : Quest
|
|
{
|
|
public CollectQuest(GameObject display) : base(display)
|
|
{
|
|
current = 0;
|
|
goal = getRandomNumber(10) + 1;
|
|
questname = "Collect " + goal + " ";
|
|
int index = getRandomNumber(11);
|
|
switch (index)
|
|
{
|
|
case 0:
|
|
questname = questname + "slimeball";
|
|
keyword = "Slimeball";
|
|
break;
|
|
case 1:
|
|
questname = questname + "rock";
|
|
keyword = "Rock";
|
|
break;
|
|
case 2:
|
|
questname = questname + "wood";
|
|
keyword = "Wood";
|
|
break;
|
|
case 3:
|
|
questname = questname + "common item";
|
|
keyword = "Common";
|
|
break;
|
|
case 4:
|
|
questname = questname + "rare item";
|
|
keyword = "Rare";
|
|
break;
|
|
case 5:
|
|
questname = questname + "epic item";
|
|
keyword = "Epic";
|
|
break;
|
|
case 6:
|
|
questname = questname + "legendary item";
|
|
keyword = "Legendary";
|
|
break;
|
|
case 7:
|
|
questname = questname + "Iron ore";
|
|
keyword = "Iron";
|
|
break;
|
|
case 8:
|
|
questname = questname + "Gold ore";
|
|
keyword = "Gold";
|
|
break;
|
|
case 9:
|
|
questname = questname + "Copper ore";
|
|
keyword = "Copper";
|
|
break;
|
|
case 10:
|
|
questname = questname + "Tin ore";
|
|
keyword = "Tin";
|
|
break;
|
|
}
|
|
}
|
|
|
|
public CollectQuest(JToken token, GameObject display) : base(token, display) { }
|
|
|
|
override
|
|
public void update(object obj, int amount)
|
|
{
|
|
Item item = (Item)obj;
|
|
if (checkItem(item))
|
|
{
|
|
current = current + amount;
|
|
}
|
|
if (current >= goal)
|
|
{
|
|
isFinished = true;
|
|
}
|
|
else
|
|
{
|
|
isFinished = false;
|
|
}
|
|
}
|
|
|
|
public void removeItems(Inventory inventory)
|
|
{
|
|
Item item;
|
|
int counter = 0;
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
foreach (GameObject slot in inventory.slots)
|
|
{
|
|
item = slot.GetComponent<InventorySlot>().getItem(i);
|
|
if (item != null)
|
|
{
|
|
if (checkItem(item))
|
|
{
|
|
slot.GetComponent<InventorySlot>().removeItem(i);
|
|
counter++;
|
|
}
|
|
}
|
|
if (counter == goal)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
if (counter == goal)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool checkItem(Item item)
|
|
{
|
|
bool result = false;
|
|
if (keyword == "Slimeball" && item.getName().ToLower().Contains("slimeball"))
|
|
{
|
|
return true;
|
|
}
|
|
if (keyword == "Rock" && item.getName().ToLower().Contains("rock"))
|
|
{
|
|
return true;
|
|
}
|
|
if (keyword == "Iron" && item.getName().ToLower().Contains("iron"))
|
|
{
|
|
return true;
|
|
}
|
|
if (keyword == "Gold" && item.getName().ToLower().Contains("gold"))
|
|
{
|
|
return true;
|
|
}
|
|
if (keyword == "Copper" && item.getName().ToLower().Contains("copper"))
|
|
{
|
|
return true;
|
|
}
|
|
if (keyword == "Tin" && item.getName().ToLower().Contains("tin"))
|
|
{
|
|
return true;
|
|
}
|
|
if (keyword == "Wood" && item.getName().ToLower().Contains("wood"))
|
|
{
|
|
return true;
|
|
}
|
|
if (keyword == "Common" && item.getName().ToLower().Contains("common"))
|
|
{
|
|
return true;
|
|
}
|
|
if (keyword == "Rare" && item.getName().ToLower().Contains("rare"))
|
|
{
|
|
return true;
|
|
}
|
|
if (keyword == "Epic" && item.getName().ToLower().Contains("epic"))
|
|
{
|
|
return true;
|
|
}
|
|
if (keyword == "Legendary" && item.getName().ToLower().Contains("legendary"))
|
|
{
|
|
return true;
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
}
|