public bool Equip(WeaponItem.Type type, bool forceUpdate = false) { if (type == equipedItem.type && !forceUpdate) { return(true); } if (type != WeaponItem.Type.None) { WeaponItem newItem = Arsenal.Instance.Get(type); if (newItem) { MeshFilter mf = newItem.GetComponent <MeshFilter>(); if (mf) { equipedMesh.mesh = mf.mesh; WeaponItem.Copy(newItem, equipedItem); return(true); } } } equipedItem.Clear(); equipedMesh.mesh = null; return(false); }
protected /* override*/ void OnCreate() { //base.OnCreate(); if (weapon) { mainWeapon = weapon.type; SecondaryWeapon = weapon.type2; } hp = MAX_HP; }
public WeaponItem Get(WeaponItem.Type type, bool verbose = true) { if (weaponDictionary.ContainsKey(type)) { return(weaponDictionary[type]); } if (verbose) { Debug.LogError("Arsenal : weapon dictionary doesn't contain item " + type.ToString()); } return(null); }
public void SetInput(Vector3 _direction, bool run = false, AgentBase attack = null, bool interact = false) { direction = _direction; this.runButton = run; this.interactButton = interact; if (attack && toAttack != attack) { { var newEquipment = currentEquipment; var source = attack as ResourceSource; if (source) { if (source.resource == ResourceSource.ResourceType.Wood) { newEquipment = WeaponItem.Type.AxeA; } else if (source.resource == ResourceSource.ResourceType.Stone) { newEquipment = WeaponItem.Type.Pickaxe; } else if (source.resource == ResourceSource.ResourceType.Gold) { newEquipment = WeaponItem.Type.Pickaxe; } else if (source.resource == ResourceSource.ResourceType.Food) { newEquipment = WeaponItem.Type.None; } } else { var building = attack as BuildingBase; if (building && building.team == this.GetComponent <AgentBase>().team) { newEquipment = WeaponItem.Type.Hammer; } else { newEquipment = character.mainWeapon; } } if (newEquipment != currentEquipment) { weapon.Equip(newEquipment, false); currentEquipment = newEquipment; AnimationParameterRefresh(); } } } this.toAttack = attack; }
public GameObject GetPickable(WeaponItem.Type type, bool showName = false, bool destroyOnPick = true) { WeaponItem item = Get(type); if (!item) { return(null); } GameObject go = Instantiate(pickablePrefab.gameObject); go.name = type.ToString(); go.transform.parent = null; go.transform.position = Vector3.zero; go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; go.AddComponent <InteractionType>().type = InteractionType.Type.pickableWeapon; WeaponItem.Copy(item, go.AddComponent <WeaponItem>()); go.SetActive(true); MeshFilter mf = item.gameObject.GetComponent <MeshFilter>(); SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>(); pickable.textmesh.text = go.name; if (go.name.Length >= 8) { pickable.textmesh.characterSize *= 0.5f; } if (mf) { pickable.itemMesh.mesh = mf.mesh; } else { pickable.itemMesh.gameObject.SetActive(false); } pickable.body.gameObject.SetActive(false); pickable.textmesh.gameObject.SetActive(showName); go.GetComponent <Item>().destroyOnPick = destroyOnPick; return(go); }
void Update() { if (weapon) { if (weapon.type != lastType) { if (mapping.ContainsKey(lastType)) { mapping[lastType].SetActive(false); } if (mapping.ContainsKey(weapon.type)) { mapping[weapon.type].SetActive(true); } } lastType = weapon.type; } else { weapon = transform.parent.gameObject.GetComponent <WeaponItem>(); } }