123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using KairoEngine.Core;
- using KairoEngine.Inventory;
- namespace KairoEngine.CharacterSystem
- {
- public class DropItemAction : IAction
- {
- ItemContainer itemContainer; // Reference to the character that will move
- ItemRef itemRef;
-
- public DropItemAction(ItemContainer itemContainer, ItemRef itemRef)
- {
- this.itemContainer = itemContainer;
- this.itemRef = itemRef;
- }
- public void Start()
- {
- itemContainer.RemoveItem(itemRef);
- Vector3 pos = itemContainer.transform.position;
- pos.y += 1.5f;
- pos.x += Random.Range(-1, 1);
- pos.z += Random.Range(-1, 1);
- GameObject obj = GameObject.Instantiate(itemRef.item.prefab, pos, itemContainer.transform.rotation);
- WorldItem worldItem = obj.GetComponent<WorldItem>();
- worldItem.itemName = itemRef.item.title;
- worldItem.quantity = itemRef.quantity;
- worldItem.lastUsed = itemRef.lastUsed;
- SerializerWorldItem serializer = obj.GetComponent<SerializerWorldItem>();
- serializer.loadedFromData = true;
- if(itemRef.item.category == ItemType.firearm)
- {
- ItemFirearmRef firearmRef = (ItemFirearmRef)itemRef;
- worldItem.itemAmmoName = firearmRef.ammoType.title;
- worldItem.ammoQuantity = firearmRef.ammo;
- }
- CharacterController character = itemContainer.GetComponent<CharacterController>();
- if(character !=null)
- {
- if(character.GetEquipedItem() == itemRef)
- {
- GameObject.Destroy(character.GetEquipedGameObject());
- character.SetEquipedItem(null);
- character.SetEquipedGameObject(null);
- character.animator.SetInteger("Mode", 0);
- }
- }
- }
- public void Update()
- {
-
- }
- public void End()
- {
-
- }
- public bool IsDone()
- {
- return true;
- }
- }
- }
|