コード例 #1
0
    public void AddToken(Token token)
    {
        Type listType;

        listType = Heroes.GetListType();
        if (listType.IsCompatibleWith(token.GetType()))
        {
            AllTokens.Add(token);
            Heroes.Add((Hero)token);
            return;
        }

        listType = Enemies.GetListType();
        if (listType.IsCompatibleWith(token.GetType()))
        {
            AllTokens.Add(token);
            Enemies.Add((Enemy)token);
            return;
        }

        listType = Farmers.GetListType();
        if (listType.IsCompatibleWith(token.GetType()))
        {
            AllTokens.Add(token);
            Farmers.Add((Farmer)token);
            return;
        }

        if (token is Fog)
        {
            AllTokens.Add(token);
            return;
        }

        if (token is Well)
        {
            AllTokens.Add(token);
            Well = (Well)token;
            return;
        }

        if (token is Witch)
        {
            AllTokens.Add(token);
            return;
        }

        if (token is Thorald)
        {
            AllTokens.Add(token);
            return;
        }

        // if none of these options means its an item
        AddItem(token);
    }
コード例 #2
0
    public void RemoveToken(int objectIndex)
    {
        if (objectIndex > AllTokens.Count - 1 || objectIndex < 0)
        {
            return;
        }

        Token token = AllTokens[objectIndex];

        AllTokens.Remove(token);

        Type listType = Heroes.GetListType();

        if (listType.IsCompatibleWith(token.GetType()))
        {
            Heroes.Remove((Hero)token);
            InventoryUICell.instance.ForceUpdate(this, cellID);
            return;
        }

        listType = Enemies.GetListType();
        if (listType.IsCompatibleWith(token.GetType()))
        {
            Enemies.Remove((Enemy)token);
            InventoryUICell.instance.ForceUpdate(this, cellID);
            return;
        }

        listType = Farmers.GetListType();
        if (listType.IsCompatibleWith(token.GetType()))
        {
            Farmers.Remove((Farmer)token);
            InventoryUICell.instance.ForceUpdate(this, cellID);
            return;
        }

        if (typeof(Well).IsCompatibleWith(token.GetType()))
        {
            Well = null;
            InventoryUICell.instance.ForceUpdate(this, cellID);
            return;
        }

        InventoryUICell.instance.ForceUpdate(this, cellID);
    }