public static Creature LoadCreature(string resref, AuroraGIT.ACreature gitData) { AuroraUTC ac = data.Get <AuroraUTC>(resref, ResourceType.UTC); Creature c = Creature.Create(ac, gitData); return(c); }
public Item GetMainWeapon() { AuroraUTC utc = (AuroraUTC)template; foreach (AuroraUTC.AEquip_Item equipped in utc.Equip_ItemList) { if (equipped.structid == 16) { // Main weapon is in slot 16 string resref = equipped.EquippedRes; Item item = Resources.LoadItem(resref); return(item); } } return(null); }
AuroraObject CreatePC() { // Create the PC GameObject player = GameObject.FindGameObjectWithTag("Player"); AuroraObject pcObj = player.AddComponent <Creature>(); stateManager.PC = pcObj; // Set the PC as the leader of the party stateManager.party[0] = pcObj; AuroraUTC template = new AuroraUTC(); // Initialize the lists template.ClassList = new List <AuroraUTC.AClass>(); template.Equip_ItemList = new List <AuroraUTC.AEquip_Item>(); template.FeatList = new List <AuroraUTC.AFeat>(); template.ItemList = new List <AuroraUTC.AItem>(); template.SkillList = new List <AuroraUTC.ASkill>(); template.SpecAbilityList = new List <AuroraUTC.ASpecAbility>(); // TODO: Temporary stuff; this should be set by character creation later // Set some default scripts template.ScriptUserDefine = "k_def_userdef01"; // Set some default variable values template.Gender = 0; template.ClassList.Add(new AuroraUTC.AClass() { structid = 0, Class = 0, ClassLevel = 1 }); pcObj.template = template; return(pcObj); }
public static Creature Create(AuroraUTC utc, AuroraGIT.ACreature gitData) { //GameObject gameObject; //get the resource reference for this object, which we'll use as it's in-engine name string name = utc.TemplateResRef; //get the appearance row number in appearance.2da int appearance = utc.Appearance_Type; string modelType = Resources.From2DA("appearance", appearance, "modeltype"); //get the model name for this appearance id string modelRef = Resources.Load2DA("appearance")[appearance, "modela"]; if (modelRef == null) { // This should only happen if we didn't find the row in appearance modelRef = Resources.Load2DA("appearance")[appearance, "race"]; } string texRef = Resources.Load2DA("appearance")[appearance, "texa"]; string cubemapRef = Resources.From2DA("appearance", appearance, "envmap"); if (Resources.data.GetStream(modelRef, ResourceType.MDL) == null) { modelRef = Resources.Load2DA("appearance")[appearance, "modelb"]; texRef = Resources.Load2DA("appearance")[appearance, "texb"]; } if (cubemapRef == "" || cubemapRef == "DEFAULT") { cubemapRef = null; } //create a new game object and load the model into the scene GameObject gameObject = Resources.LoadModel(modelRef, null, null, cubemapRef); gameObject.name = name; GameObject headObj = null; switch (modelType.ToLower()) { case "b": // Model requires a head int headID = int.Parse(Resources.From2DA("appearance", appearance, "normalhead")); string headName = Resources.From2DA("heads", headID, "head"); headObj = Resources.LoadModel(headName, null, gameObject, cubemapRef); break; case "f": default: // Model includes head break; } // Add a character controller for movement NavMeshAgent agent = gameObject.AddComponent <NavMeshAgent>(); // Make the creature commandable by default utc.Commandable = 1; //add the template component to the new object Creature creature = gameObject.AddComponent <Creature>(); creature.template = utc; creature.gitData = gitData; creature.head = headObj; LookAtHook hook = gameObject.GetComponentInChildren <LookAtHook>(); if (hook != null) { hook.obj = creature; } //if (headObj != null) //{ // Transform headPosition = gameObject.transform.Find("cutscenedummy/rootdummy/torso_g/torsoupr_g/headhook"); // character.head.transform.localPosition = headPosition.position - character.head.transform.position; // character.head.transform.localRotation = Quaternion.identity; //} return(creature); }
void DrawHooks() { selectedHook = null; GUIStyle style = new GUIStyle(); style.fontSize = 16; style.normal.textColor = Color.red; style.alignment = TextAnchor.MiddleCenter; List <GameObject> allHooks = new List <GameObject>(); foreach (GameObject obj in GameObject.FindGameObjectsWithTag("LookAtHook")) { //Debug.Log("Considering object " + obj.name); AuroraObject auroraObject = obj.GetComponent <LookAtHook>().obj; if (auroraObject == null) { continue; } if (auroraObject.GetType() == typeof(Door)) { Door door = (Door)auroraObject; AuroraUTD utd = (AuroraUTD)door.template; // TODO: Support closing doors? Don't think this is a thing in KotOR/TSL if (door.open) { //Debug.Log("Door is open, so not drawing hook"); continue; } //Debug.Log("Drawing hook for door"); allHooks.Add(obj); } else if (auroraObject.GetType() == typeof(Creature)) { // Check if the creature has a default conversation Creature creature = (Creature)auroraObject; AuroraUTC utc = (AuroraUTC)creature.template; bool selectable = false; if (utc.Conversation == null || utc.Conversation == "") { //Debug.Log("Creature has no conversation, so not drawing hook"); selectable = true; } else if (NWScript.GetIsEnemy(creature, stateSystem.PC) > 0) { selectable = true; } if (selectable) { allHooks.Add(obj); } } else if (auroraObject.GetType() == typeof(Placeable)) { // Check if the placeable can be interacted with Placeable placeable = (Placeable)auroraObject; AuroraUTP utp = (AuroraUTP)placeable.template; if (utp.Useable == 0) { //Debug.Log("Placeable is not useable, so not drawing hook"); continue; } //Debug.Log("Drawing hook for placeable"); allHooks.Add(obj); } } //Debug.Log("Considering " + allHooks.Count + " hooks"); List <GameObject> hooks = new List <GameObject>(); foreach (GameObject g in allHooks) { //Debug.Log("Checking if hook " + g.name + " is visible"); // Determine whether the object is blocked by another collider Vector2 point = Camera.main.WorldToScreenPoint(g.transform.position); Ray r = Camera.main.ScreenPointToRay(point); RaycastHit hit; if (Physics.Raycast(r, out hit, float.MaxValue, hookMask)) { // We might hit the boundary of the object represented by the hook? if (hit.transform.gameObject == g || Vector3.Distance(hit.point, g.transform.position) < 1f) { hooks.Add(g); } } } //Debug.Log("Showing " + hooks.Count + " hooks"); float dist = float.PositiveInfinity; selectedHook = null; foreach (GameObject h in hooks) { Vector2 hPos = Camera.main.WorldToScreenPoint(h.transform.position); float d = Vector2.Distance( new Vector2(hPos.x, Screen.height - hPos.y), new Vector2( Screen.width / 2, Screen.height / 2 ) ); if (d < dist) { dist = d; selectedHook = h; } } foreach (GameObject g in hooks) { Vector2 point = Camera.main.WorldToScreenPoint(g.transform.position); if (g == selectedHook) { if (Vector3.Distance(pc.transform.position, selectedHook.transform.position) < interactionRange) { style.normal.textColor = Color.green; style.fontSize = 28; } else { style.normal.textColor = Color.blue; style.fontSize = 28; } } else { style.normal.textColor = Color.red; style.fontSize = 16; } Rect labelRect = new Rect(point.x - 90, Screen.height - point.y - 240, 180, 240); AuroraObject obj = g.GetComponent <LookAtHook>().obj; if (obj.GetType() == typeof(Door)) { TooltipWindow doorTooltip = ((Door)obj).GetTooltip(); using (new GUILayout.AreaScope(labelRect)) { doorTooltip.Draw(); } } GUI.Label( new Rect(point.x - 25, Screen.height - point.y - 25, 50, 50), "O", style );; } }