public Entity SpawnItem(ItemSpawnInfo itemSpawnInfo) { Item item = DBManager.GetItemInfo(itemSpawnInfo.AID); string itemPath = DBManager.GetItemPath(itemSpawnInfo.AID, itemSpawnInfo.IsIdentified); ACT act = FileManager.Load(itemPath + ".act") as ACT; SPR spr = FileManager.Load(itemPath + ".spr") as SPR; var itemGO = new GameObject(item.identifiedDisplayName); itemGO.layer = LayerMask.NameToLayer("Items"); itemGO.transform.localScale = Vector3.one; itemGO.transform.localPosition = itemSpawnInfo.Position; var entity = itemGO.AddComponent <Entity>(); var body = new GameObject("Body"); body.layer = LayerMask.NameToLayer("Items"); body.transform.SetParent(itemGO.transform, false); body.transform.localPosition = new Vector3(0.5f, 0.4f, 0.5f); body.AddComponent <Billboard>(); body.AddComponent <SortingGroup>(); if (itemSpawnInfo.animate) { var animator = body.AddComponent <Animator>(); animator.runtimeAnimatorController = Instantiate(Resources.Load("Animations/ItemDropAnimator")) as RuntimeAnimatorController; } var bodyViewer = body.AddComponent <EntityViewer>(); entity.EntityViewer = bodyViewer; entity.Type = EntityType.ITEM; entity.ShadowSize = 0.5f; bodyViewer.ViewerType = ViewerType.BODY; bodyViewer.Entity = entity; bodyViewer.SpriteOffset = 0.5f; bodyViewer.HeadDirection = 0; bodyViewer.CurrentMotion = new EntityViewer.MotionRequest { Motion = SpriteMotion.Idle }; entity.Init(spr, act); entity.AID = (uint)itemSpawnInfo.mapID; entityCache.Add(entity.AID, entity); entity.SetReady(true); return(entity); }
public Entity SpawnItem(ItemSpawnInfo itemSpawnInfo) { Item item = DBManager.GetItemInfo(itemSpawnInfo.GID); string itemPath = DBManager.GetItemPath(itemSpawnInfo.GID, itemSpawnInfo.IsIdentified); ACT act = FileManager.Load(itemPath + ".act") as ACT; SPR spr = FileManager.Load(itemPath + ".spr") as SPR; var itemGO = new GameObject(item.identifiedDisplayName); itemGO.layer = LayerMask.NameToLayer("Items"); itemGO.transform.localScale = Vector3.one; var entity = itemGO.AddComponent <Entity>(); var body = new GameObject("Body"); body.layer = LayerMask.NameToLayer("Items"); body.transform.SetParent(itemGO.transform, false); body.transform.localPosition = itemSpawnInfo.Position; body.AddComponent <Billboard>(); body.AddComponent <SortingGroup>(); var bodyViewer = body.AddComponent <EntityViewer>(); entity.EntityViewer = bodyViewer; entity.Type = EntityType.ITEM; bodyViewer.ViewerType = ViewerType.BODY; bodyViewer.Entity = entity; bodyViewer.SpriteOffset = 0.5f; bodyViewer.HeadDirection = 0; bodyViewer.CurrentMotion = SpriteMotion.Idle; bodyViewer.Type = entity.Type; entity.Init(spr, act); entity.GID = (uint)itemSpawnInfo.mapID; entity.SetReady(true); return(entity); }
protected StatusEffect(XElement element, string parentDebugName) { requiredItems = new List <RelatedItem>(); spawnItems = new List <ItemSpawnInfo>(); Afflictions = new List <Affliction>(); ReduceAffliction = new List <Pair <string, float> >(); tags = new HashSet <string>(element.GetAttributeString("tags", "").Split(',')); Range = element.GetAttributeFloat("range", 0.0f); IEnumerable <XAttribute> attributes = element.Attributes(); List <XAttribute> propertyAttributes = new List <XAttribute>(); propertyConditionals = new List <PropertyConditional>(); foreach (XAttribute attribute in attributes) { switch (attribute.Name.ToString()) { case "type": if (!Enum.TryParse(attribute.Value, true, out type)) { DebugConsole.ThrowError("Invalid action type \"" + attribute.Value + "\" in StatusEffect (" + parentDebugName + ")"); } break; case "target": string[] Flags = attribute.Value.Split(','); foreach (string s in Flags) { if (!Enum.TryParse(s, true, out TargetType targetType)) { DebugConsole.ThrowError("Invalid target type \"" + s + "\" in StatusEffect (" + parentDebugName + ")"); } else { targetTypes |= targetType; } } break; case "disabledeltatime": disableDeltaTime = attribute.GetAttributeBool(false); break; case "setvalue": setValue = attribute.GetAttributeBool(false); break; case "targetnames": DebugConsole.ThrowError("Error in StatusEffect config (" + parentDebugName + ") - use identifiers or tags to define the targets instead of names."); break; case "targetidentifiers": string[] identifiers = attribute.Value.Split(','); targetIdentifiers = new HashSet <string>(); for (int i = 0; i < identifiers.Length; i++) { targetIdentifiers.Add(identifiers[i].Trim().ToLowerInvariant()); } break; case "duration": duration = attribute.GetAttributeFloat(0.0f); break; case "stackable": Stackable = attribute.GetAttributeBool(true); break; case "checkconditionalalways": CheckConditionalAlways = attribute.GetAttributeBool(false); break; case "conditionalcomparison": case "comparison": if (!Enum.TryParse(attribute.Value, out conditionalComparison)) { DebugConsole.ThrowError("Invalid conditional comparison type \"" + attribute.Value + "\" in StatusEffect (" + parentDebugName + ")"); } break; case "sound": DebugConsole.ThrowError("Error in StatusEffect " + element.Parent.Name.ToString() + " - sounds should be defined as child elements of the StatusEffect, not as attributes."); break; default: propertyAttributes.Add(attribute); break; } } int count = propertyAttributes.Count; propertyNames = new string[count]; propertyEffects = new object[count]; int n = 0; foreach (XAttribute attribute in propertyAttributes) { propertyNames[n] = attribute.Name.ToString().ToLowerInvariant(); propertyEffects[n] = XMLExtensions.GetAttributeObject(attribute); n++; } foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "explosion": explosion = new Explosion(subElement, parentDebugName); break; case "fire": FireSize = subElement.GetAttributeFloat("size", 10.0f); break; case "use": case "useitem": useItemCount++; break; case "remove": case "removeitem": removeItem = true; break; case "requireditem": case "requireditems": RelatedItem newRequiredItem = RelatedItem.Load(subElement, parentDebugName); if (newRequiredItem == null) { DebugConsole.ThrowError("Error in StatusEffect config - requires an item with no identifiers."); continue; } requiredItems.Add(newRequiredItem); break; case "conditional": IEnumerable <XAttribute> conditionalAttributes = subElement.Attributes(); foreach (XAttribute attribute in conditionalAttributes) { if (attribute.Name.ToString().ToLowerInvariant() == "targetitemcomponent") { continue; } propertyConditionals.Add(new PropertyConditional(attribute)); } break; case "affliction": AfflictionPrefab afflictionPrefab; if (subElement.Attribute("name") != null) { DebugConsole.ThrowError("Error in StatusEffect (" + parentDebugName + ") - define afflictions using identifiers instead of names."); string afflictionName = subElement.GetAttributeString("name", "").ToLowerInvariant(); afflictionPrefab = AfflictionPrefab.List.Find(ap => ap.Name.ToLowerInvariant() == afflictionName); if (afflictionPrefab == null) { DebugConsole.ThrowError("Error in StatusEffect (" + parentDebugName + ") - Affliction prefab \"" + afflictionName + "\" not found."); continue; } } else { string afflictionIdentifier = subElement.GetAttributeString("identifier", "").ToLowerInvariant(); afflictionPrefab = AfflictionPrefab.List.Find(ap => ap.Identifier.ToLowerInvariant() == afflictionIdentifier); if (afflictionPrefab == null) { DebugConsole.ThrowError("Error in StatusEffect (" + parentDebugName + ") - Affliction prefab with the identifier \"" + afflictionIdentifier + "\" not found."); continue; } } float afflictionStrength = subElement.GetAttributeFloat(1.0f, "amount", "strength"); Afflictions.Add(afflictionPrefab.Instantiate(afflictionStrength)); break; case "reduceaffliction": if (subElement.Attribute("name") != null) { DebugConsole.ThrowError("Error in StatusEffect (" + parentDebugName + ") - define afflictions using identifiers or types instead of names."); ReduceAffliction.Add(new Pair <string, float>( subElement.GetAttributeString("name", "").ToLowerInvariant(), subElement.GetAttributeFloat(1.0f, "amount", "strength", "reduceamount"))); } else { string name = subElement.GetAttributeString("identifier", null) ?? subElement.GetAttributeString("type", null); name = name.ToLowerInvariant(); if (AfflictionPrefab.List.Any(ap => ap.Identifier == name || ap.AfflictionType == name)) { ReduceAffliction.Add(new Pair <string, float>( name, subElement.GetAttributeFloat(1.0f, "amount", "strength", "reduceamount"))); } else { DebugConsole.ThrowError("Error in StatusEffect (" + parentDebugName + ") - Affliction prefab with the identifier or type \"" + name + "\" not found."); } } break; case "spawnitem": var newSpawnItem = new ItemSpawnInfo(subElement, parentDebugName); if (newSpawnItem.ItemPrefab != null) { spawnItems.Add(newSpawnItem); } break; } } InitProjSpecific(element, parentDebugName); }