public List <Skill> SkillsAssociatedWith(WorldItem targetObject) { HashSet <Skill> skills = new HashSet <Skill> (); Skill examineSkill = null; Skill reverseEngineerSkill = null; if (mSkillsLookup.TryGetValue("Examine", out examineSkill)) { skills.Add(examineSkill); } if (mSkillsLookup.TryGetValue("ReverseEngineer", out reverseEngineerSkill)) { skills.Add(reverseEngineerSkill); } List <Skill> associatedNameSkills; if (mSkillsLookupByWorldItem.TryGetValue(targetObject.StackName, out associatedNameSkills)) { var enumerator = associatedNameSkills.GetEnumerator(); while (enumerator.MoveNext()) { skills.Add(enumerator.Current); } } WorldItem worlditem = targetObject.GetComponent <WorldItem> (); if (worlditem != null) { #if DEBUG_SKILLS Debug.Log("Skills associated with " + targetObject.name); #endif var enumerator = worlditem.ScriptNames.GetEnumerator(); while (enumerator.MoveNext()) { List <Skill> associatedScriptSkills = null; #if DEBUG_SKILLS Debug.Log(" - Checking " + enumerator.Current); #endif if (mSkillsLookupByWIScript.TryGetValue(enumerator.Current, out associatedScriptSkills)) { var associatedEnumerator = associatedScriptSkills.GetEnumerator(); while (associatedEnumerator.MoveNext()) { #if DEBUG_SKILLS Debug.Log(" - Adding " + associatedEnumerator.Current.name); #endif skills.Add(associatedEnumerator.Current); } } } } List <Skill> finalSkillList = new List <Skill> (skills); finalSkillList.Sort(); return(finalSkillList); }
public void OnDie() { switch (worlditem.State) { case "Mined": Debug.Log("DIED in luminite node with state mined"); worlditem.Get <Damageable> ().ResetDamage(); State.TimeMined = WorldClock.AdjustedRealTime; break; default: Debug.Log("DIED in luminite node with state " + worlditem.State); worlditem.Get <Damageable> ().ResetDamage(); //set luminite type to mined raw, then get a stack item for the player //add that to player inventory WorldItem rawLuminite = null; GenericWorldItem rawLuminiteItem = RawLuminiteLight; if (worlditem.State == "Dark") { rawLuminiteItem = RawLuminiteDark; } if (WorldItems.CloneWorldItem( rawLuminiteItem, new STransform(worlditem.tr), false, worlditem.Group, out rawLuminite)) { //this will drop to the players' feet rawLuminite.Props.Local.FreezeOnStartup = false; rawLuminite.Initialize(); rawLuminite.SetMode(WIMode.World); rawLuminite.GetComponent <Rigidbody>().AddForce(worlditem.tr.up * 0.25f); } State.TimeMined = WorldClock.AdjustedRealTime; State.AbsorbedDarkRot = 0f; worlditem.State = "Mined"; break; } Debug.Log("State is now " + worlditem.State); }
public void DropLoot() { List <WorldItem> theDrop = lootTable.CreateDrop(); if (theDrop != null && theDrop.Count > 0) { foreach (var item in theDrop) { GameObject itemBeingCreated = Instantiate(Resources.Load("BlankItem")) as GameObject; WorldItem wI = itemBeingCreated.GetComponent <WorldItem>(); wI.inventoryItem = item.inventoryItem.Clone(); wI.transform.position = new Vector3(UnityEngine.Random.Range(-.25f, .25f) + transform.position.x, .25f + transform.position.y, UnityEngine.Random.Range(-.25f, .25f) + transform.position.z); wI.transform.LookAt(transform); wI.transform.Rotate(0, 180, 0); wI.GetComponent <Rigidbody>().velocity = itemBeingCreated.transform.forward * UnityEngine.Random.Range(4f, 7f); wI.transform.rotation = UnityEngine.Random.rotation; wI.transform.SetParent(GameObject.Find("Items").transform); wI.gameObject.SetActive(true); } } }
public bool TossItem(InventoryItem itemToRemove, int index) { if (RemoveItem(index)) { RootUnit unitToDrop = GameWorldReferenceClass.GetUnitByID(owner); Vector3 pos = unitToDrop.transform.position; if (ResourceManager.AllWorldItems.Count > 0) { WorldItem itemBeingCreated = ResourceManager.RestoreItem(); itemBeingCreated.inventoryItem = itemToRemove; itemBeingCreated.transform.position = new Vector3(UnityEngine.Random.Range(-.25f, .25f) + pos.x, .25f + pos.y, UnityEngine.Random.Range(-.25f, .25f) + pos.z); itemBeingCreated.transform.LookAt(unitToDrop.transform); itemBeingCreated.transform.Rotate(0, 180, 0); itemBeingCreated.GetComponent <Rigidbody>().velocity = itemBeingCreated.transform.forward * UnityEngine.Random.Range(4f, 7f); itemBeingCreated.transform.rotation = UnityEngine.Random.rotation; itemBeingCreated.transform.SetParent(GameObject.Find("Items").transform); itemBeingCreated.gameObject.SetActive(true); return(true); } else { GameObject freshWorldItem = GameObject.Instantiate(Resources.Load("BlankItem")) as GameObject; WorldItem itemBeingCreated = freshWorldItem.GetComponent <WorldItem>(); itemBeingCreated.inventoryItem = itemToRemove; itemBeingCreated.transform.position = new Vector3(UnityEngine.Random.Range(-.25f, .25f) + unitToDrop.transform.position.x, .25f + unitToDrop.transform.position.y, UnityEngine.Random.Range(-.25f, .25f) + unitToDrop.transform.position.z); itemBeingCreated.transform.LookAt(unitToDrop.transform); itemBeingCreated.transform.Rotate(0, 180, 0); itemBeingCreated.GetComponent <Rigidbody>().velocity = itemBeingCreated.transform.forward * UnityEngine.Random.Range(4f, 7f); itemBeingCreated.transform.rotation = UnityEngine.Random.rotation; freshWorldItem.transform.SetParent(GameObject.Find("Items").transform); return(true); } } return(false); }
public void DrawGenericWorldItemSelector(GenericWorldItem item, ref bool open, bool useStrictness) { if (WorldItems.Get == null) { Manager.WakeUp <WorldItems>("Frontiers_WorldItems"); WorldItems.Get.Initialize(); } bool drawEditor = true; UnityEditor.EditorStyles.miniButton.stretchWidth = true; UnityEditor.EditorStyles.textField.stretchWidth = true; UnityEditor.EditorStyles.popup.stretchWidth = true; GUILayout.BeginVertical(); if (string.IsNullOrEmpty(item.PackName)) { drawEditor = false; UnityEngine.GUI.color = Color.green; if (GUILayout.Button("(Add)", UnityEditor.EditorStyles.miniButton)) { item.PackName = "AncientArtifacts"; item.PrefabName = string.Empty; drawEditor = true; } UnityEngine.GUI.color = Color.yellow; if (GUILayout.Button("(Done)", UnityEditor.EditorStyles.miniButton)) { drawEditor = false; selectedItemIndex = -1; selectedRowIndex = -1; } } else { UnityEngine.GUI.color = Color.red; if (GUILayout.Button("(Clear)", UnityEditor.EditorStyles.miniButton)) { item.Clear(); drawEditor = false; } } if (drawEditor) { UnityEngine.GUI.color = Color.yellow; int packIndex = 0; List <string> packNames = new List <string>(); WorldItemPack pack = null; WorldItem worlditem = null; for (int i = 0; i < WorldItems.Get.WorldItemPacks.Count; i++) { string packName = WorldItems.Get.WorldItemPacks[i].Name; packNames.Add(packName); if (item.PackName == packName) { packIndex = i; pack = WorldItems.Get.WorldItemPacks[i]; } } if (pack == null) { pack = WorldItems.Get.WorldItemPacks[0]; } packIndex = UnityEditor.EditorGUILayout.Popup("Pack:", packIndex, packNames.ToArray(), UnityEditor.EditorStyles.popup); List <string> prefabNames = new List <string>(); int prefabIndex = 0; for (int i = 0; i < pack.Prefabs.Count; i++) { prefabNames.Add(pack.Prefabs[i].name); if (item.PrefabName == pack.Prefabs[i].name) { prefabIndex = i; worlditem = pack.Prefabs[i].GetComponent <WorldItem>(); } } prefabIndex = UnityEditor.EditorGUILayout.Popup("Prefab:", prefabIndex, prefabNames.ToArray(), UnityEditor.EditorStyles.popup); item.PackName = packNames[packIndex]; item.PrefabName = prefabNames[prefabIndex]; if (worlditem != null) { UnityEngine.GUI.color = Color.yellow; item.DisplayName = worlditem.DisplayName; if (!useStrictness || Flags.Check((uint)Blueprint.Strictness, (uint)BlueprintStrictness.StackName, Flags.CheckType.MatchAny)) { GUILayout.BeginHorizontal(); GUILayout.Label("StackName: "); if (string.IsNullOrEmpty(item.StackName) || !worlditem.StackName.Contains(item.StackName)) { item.StackName = worlditem.StackName; } item.StackName = GUILayout.TextField(item.StackName); GUILayout.EndHorizontal(); } if (!useStrictness || Flags.Check((uint)Blueprint.Strictness, (uint)BlueprintStrictness.StateName, Flags.CheckType.MatchAny)) { GUILayout.BeginHorizontal(); int stateIndex = 0; List <string> stateNames = new List <string>(); stateNames.Add("Default"); WIStates states = worlditem.GetComponent <WIStates>(); if (states != null) { for (int i = 0; i < states.States.Count; i++) { stateNames.Add(states.States[i].Name); if (item.State == states.States[i].Name) { stateIndex = i + 1; //since the first one is Default } } } stateIndex = UnityEditor.EditorGUILayout.Popup("State:", stateIndex, stateNames.ToArray(), UnityEditor.EditorStyles.popup); GUILayout.EndHorizontal(); item.State = stateNames[stateIndex]; } } UnityEngine.GUI.color = Color.white; if (!useStrictness || Flags.Check((uint)Blueprint.Strictness, (uint)BlueprintStrictness.Subcategory, Flags.CheckType.MatchAny)) { GUILayout.BeginHorizontal(); GUILayout.Label("Subcategory: "); item.Subcategory = GUILayout.TextField(item.Subcategory); GUILayout.EndHorizontal(); } UnityEngine.GUI.color = Color.yellow; if (GUILayout.Button("(Done)", UnityEditor.EditorStyles.miniButton)) { open = false; } } GUILayout.EndVertical(); UnityEditor.EditorStyles.miniButton.stretchWidth = true; UnityEditor.EditorStyles.textField.stretchWidth = true; UnityEditor.EditorStyles.popup.stretchWidth = true; }
public void RefreshToolDoppleganger(bool equipping) { if (mDopplegangerLocked) { //rogue call, probably from OnModeChange or something return; } if (!equipping) { BreakDownToolDoppleganger(); //nothing else to do here return; } else if (!HasWorldItem) { BreakDownToolDoppleganger(); } else { //we're equippping and we have a worlditem bool useDoppleganger = true; bool displayAsTool = true; Vector3 equipPos = worlditem.Props.Global.PivotOffset; Vector3 equipRot = worlditem.Props.Global.BaseRotation; Equippable equippable = null; if (worlditem.Is <Equippable> (out equippable)) { displayAsTool = equippable.DisplayAsTool; useDoppleganger = equippable.UseDoppleganger; //prep these just in case, doesn't cost us much equipPos += equippable.EquipOffset; equipRot += equippable.EquipRotation; //invert the equippable X equipPos.x = -equipPos.x; } //now, are we actually using a doppleganger? if (!displayAsTool) { BreakDownToolDoppleganger(); return; } else if (!useDoppleganger) { BreakDownToolDoppleganger(); worlditem.LockTransform(tr); worlditem.tr.localPosition = equipPos; worlditem.tr.localRotation = Quaternion.Euler(equipRot); worlditem.GetComponent <Rigidbody>().isKinematic = true; ToolColliders.AddRange(worlditem.Colliders); //and we're done return; } else { ToolDoppleganger = WorldItems.GetDoppleganger(worlditem, transform, ToolDoppleganger); ToolColliders.AddRange(ToolDoppleganger.GetComponentsInChildren <Collider> ()); //the equipped mode will apply equipped etc. offset //so don't bother to set that here ToolDoppleganger.SetActive(true); } } }
public void RefreshToolDoppleganger(bool equipping) { if (mDopplegangerLocked) { //rogue call, probably from OnModeChange or something return; } if (!equipping) { BreakDownToolDoppleganger(); //nothing else to do here return; } else if (!HasWorldItem) { BreakDownToolDoppleganger(); } else { //we're equippping and we have a worlditem bool useDoppleganger = true; bool displayAsTool = true; Vector3 equipPos = worlditem.Props.Global.PivotOffset; Vector3 equipRot = worlditem.Props.Global.BaseRotation; //Equippable equippable = null; if (worlditem.Is <Equippable>(out mEquippable)) { displayAsTool = mEquippable.DisplayAsTool; useDoppleganger = mEquippable.UseDoppleganger; //prep these just in case, doesn't cost us much equipPos += mEquippable.EquipOffset; equipRot += mEquippable.EquipRotation; } //now, are we actually using a doppleganger? if (!displayAsTool) { BreakDownToolDoppleganger(); return; } else if (!useDoppleganger) { //alright no doppleganger, but we still equip the worlditem as a tool BreakDownToolDoppleganger(); worlditem.LockTransform(tr); worlditem.tr.localPosition = equipPos; worlditem.tr.localRotation = Quaternion.Euler(equipRot); worlditem.GetComponent <Rigidbody>().isKinematic = true; ToolColliders.AddRange(worlditem.Colliders); //and we're done return; } else { //actually use doppleganger! here we go ToolDoppleganger = WorldItems.GetDoppleganger(worlditem, transform, ToolDoppleganger); ToolColliders.AddRange(ToolDoppleganger.GetComponentsInChildren <Collider>()); ToolActionPointObject = ToolDoppleganger.FindOrCreateChild("ToolActionPointObject"); //the equipped mode will apply equipped etc. offset //so don't bother to set that here ToolDoppleganger.SetActive(true); //get any tension morph animations TensionMorph = ToolDoppleganger.GetComponent <MegaMorph>(); if (TensionMorph != null) { TensionChannel = TensionMorph.GetChannel("Tension"); } //get any projectiles //Weapon weapon = null; if (worlditem.Is <Weapon>(out mWeapon)) { //update our action point //the action point is a gameobject in the weapon that indicates where hits collide //and/or where projectiles launch from - it's safe to access because it's a property ToolActionPointObject.transform.localPosition = mWeapon.ActionPointObject.transform.localPosition; ToolActionPointObject.transform.localRotation = mWeapon.ActionPointObject.transform.localRotation; if (HasProjectile) { //if we've found a projectile, create a doppleganger for it ProjectileDoppleganger = WorldItems.GetDoppleganger( ProjectileObject.PackName, ProjectileObject.PrefabName, ToolActionPointObject.transform, ProjectileDoppleganger, WIMode.Equipped, ProjectileObject.StackName, ProjectileObject.State, ProjectileObject.Subcategory, 1f, WorldClock.TimeOfDayCurrent, WorldClock.TimeOfYearCurrent); ProjectileDoppleganger.SetActive(true); } else if (ProjectileDoppleganger != null) { ProjectileDoppleganger.SetActive(false); } } else if (ProjectileDoppleganger != null) { ProjectileDoppleganger.SetActive(false); } } } }