using System.Collections; using System.Collections.Generic; using UnityEngine; using KairoEngine.Core; using KairoEngine.Inventory; namespace KairoEngine.CharacterSystem { public class CharacterEquipItemAction : IAction { ItemRef itemRef; CharacterController character; // Reference to the character that will move // Constructor public CharacterEquipItemAction(ItemRef itemRef, CharacterController character) { this.itemRef = itemRef; this.character = character; } public void Start() { //Debug.Log("Equipping Item"); if(itemRef.item.category != ItemType.firearm && itemRef.item.category != ItemType.handWeapon) return; if(character.HasEquipedItem()) { GameObject.Destroy(character.GetEquipedGameObject()); character.SetEquipedItem(null); } GameObject weaponObj; ItemBaseHoldable holdableItem = (ItemBaseHoldable)itemRef.item; weaponObj = GameObject.Instantiate(holdableItem.holdablePrefab, character.rightHand.transform); holdableItem.Setup(weaponObj, 1f); character.animator.SetInteger("Mode", holdableItem.animationMode); character.SetEquipedItem(itemRef); character.SetEquipedGameObject(weaponObj); if(itemRef.item.category == ItemType.firearm) { ItemBaseFirearm weaponItem = (ItemBaseFirearm)itemRef.item; if(weaponItem.firearmType == FirearmType.pistol) character.animator.SetBool("Pistol", true); else character.animator.SetBool("Pistol", false); Firearm firearm = character.GetEquipedGameObject().GetComponent(); if(firearm != null) { ItemFirearmRef firearmRef = itemRef as ItemFirearmRef; if(firearmRef == null) { Debug.LogError("Cast is not working for item " + itemRef.item.title); //firearmRef = new ItemFirearmRef(weaponItem, itemRef.quantity, weaponItem.ammoType, 0); //itemRef = firearmRef; //character.itemContainer.UpdateItem(itemRef); } firearm.itemFirearmRef = firearmRef; } } else if(itemRef.item.category == ItemType.handWeapon) { ItemBaseHandWeapon weaponItem = (ItemBaseHandWeapon)itemRef.item; DamageEmitter damageEmitter = character.GetEquipedGameObject().GetComponent(); damageEmitter.character = character; damageEmitter.damage = weaponItem.damage; HandWeapon handWeapon = weaponObj.GetComponent(); if(handWeapon != null) { handWeapon.weaponCollider.enabled = false; handWeapon.damageTrigger.enabled = true; } } } public void Update() { } public void End() { } public bool IsDone() { return true; } } }