Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Devdog.Rucksack;
- using Devdog.Rucksack.CharacterEquipment;
- using Devdog.Rucksack.UI;
- using Devdog.Rucksack.Characters;
- using Devdog.Rucksack.CharacterEquipment.Items;
- using Devdog.Rucksack.Collections;
- using UnityEngine;
- using System.Collections.Generic;
- using System;
- using System.Collections;
- using Devdog.Rucksack.Items;
- using UnityEngine.Networking;
- using Devdog.Rucksack.Database;
- using static Devdog.Rucksack.Collections.ICollection;
- public class MyEquipableCharacter : UNetEquippableCharacter
- {
- public UNetInventoryPlayer invPlayer;
- public UNetEquipmentCollectionCreator equipmentInv;
- public UNetItemCollectionCreator weaponsInv;
- public UNetItemCollectionCreator defenseInv;
- public UNetItemCollectionCreator shipInv;
- public UNetItemCollectionCreator heroesInv;
- [SerializeField] public UnityItemDefinitionDatabase _myDataBase;
- public void SetSlot(ushort index, ushort amount)
- {
- foreach (var conn in NetworkServer.connections)
- {
- if (conn != null)
- {
- if (IsValidConnection(conn))
- {
- bridge.TargetRpc_SetSlot(conn, new SlotDataMessage()
- {
- collectionGuid = equipmentInv.collection.ID,
- itemInstanceGuid = System.Guid.Empty,
- index = index,
- amount = amount
- });
- }
- }
- }
- }
- public override Result<EquipmentResult<IEquippableItemInstance>[]> Equip(IEquippableItemInstance item, int amount = 1)
- {
- var equipped = base.Equip(item, amount);
- if (equipped.error != null)
- {
- Debug.Log("Error: " + equipped.error);
- }
- return equipped;
- }
- public override Result<EquipmentResult<IEquippableItemInstance>> EquipAt(int index, IEquippableItemInstance item, int amount = 1)
- {
- var equipped = base.EquipAt(index, item, amount);
- if (equipped.error != null)
- {
- Debug.Log("Error: " + equipped.error);
- }
- return equipped;
- }
- public override Result<UnEquipmentResult> UnEquip(IEquippableItemInstance item, int amount = 1)
- {
- Debug.Log("Unequip Method");
- var collection = equipmentInv.collection;
- var index = collection.IndexOf(item);
- var unEquipped = base.UnEquip(item, amount);
- if(unEquipped.error == null)
- {
- SendTargetRpc_NotifyItemUnEquipped(unEquipped.result.mountPoint);
- SetSlot((ushort)index, (ushort)amount);
- collection.Set(index, null, 0);
- string collectionName = item.itemDefinition.collectionName;
- if (collectionName == weaponsInv.collectionName)
- {
- Debug.Log("Weapons UI Collection: " + weaponsInv.collection);
- var col = weaponsInv.collection as Devdog.Rucksack.Collections.ICollection<IItemInstance>;
- col.Add(item);
- }
- else if (collectionName == defenseInv.collectionName)
- {
- Debug.Log("Defense UI Collection: " + defenseInv.collection);
- var col = defenseInv.collection as Devdog.Rucksack.Collections.ICollection<IItemInstance>;
- col.Add(item);
- }
- return unEquipped;
- }
- else
- {
- Debug.Log("Error: " + unEquipped.error);
- return new Result<UnEquipmentResult>(new UnEquipmentResult()
- {
- });
- }
- }
- public override Result<UnEquipmentResult> UnEquipAt(int index, int amount = 1)
- {
- Debug.Log("UnequipAt Method");
- var collection = equipmentInv.collection;
- var item = collection[index];
- var unEquipped = base.UnEquipAt(index, amount);
- if (unEquipped.error == null)
- {
- SendTargetRpc_NotifyItemUnEquipped(unEquipped.result.mountPoint);
- string collectionName = item.itemDefinition.collectionName;
- if (collectionName == weaponsInv.collectionName)
- {
- Debug.Log("Weapons UI Collection: " + weaponsInv.collection);
- var col = weaponsInv.collection as Devdog.Rucksack.Collections.ICollection<IItemInstance>;
- col.Add(item);
- }
- else if (collectionName == defenseInv.collectionName)
- {
- Debug.Log("Defense UI Collection: " + defenseInv.collection);
- var col = defenseInv.collection as Devdog.Rucksack.Collections.ICollection<IItemInstance>;
- col.Add(item);
- }
- return unEquipped;
- }
- else
- {
- Debug.Log("Error: " + unEquipped.error);
- return new Result<UnEquipmentResult>(new UnEquipmentResult()
- {
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement