public ItemComponent(Item item, XElement element) { this.item = item; originalElement = element; name = element.Name.ToString(); SerializableProperties = SerializableProperty.GetProperties(this); requiredItems = new Dictionary <RelatedItem.RelationType, List <RelatedItem> >(); requiredSkills = new List <Skill>(); #if CLIENT hasSoundsOfType = new bool[Enum.GetValues(typeof(ActionType)).Length]; sounds = new Dictionary <ActionType, List <ItemSound> >(); #endif SelectKey = InputType.Select; try { string selectKeyStr = element.GetAttributeString("selectkey", "Select"); selectKeyStr = ToolBox.ConvertInputType(selectKeyStr); SelectKey = (InputType)Enum.Parse(typeof(InputType), selectKeyStr, true); } catch (Exception e) { DebugConsole.ThrowError("Invalid select key in " + element + "!", e); } PickKey = InputType.Select; try { string pickKeyStr = element.GetAttributeString("pickkey", "Select"); pickKeyStr = ToolBox.ConvertInputType(pickKeyStr); PickKey = (InputType)Enum.Parse(typeof(InputType), pickKeyStr, true); } catch (Exception e) { DebugConsole.ThrowError("Invalid pick key in " + element + "!", e); } SerializableProperties = SerializableProperty.DeserializeProperties(this, element); ParseMsg(); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "activeconditional": case "isactive": IsActiveConditionals = IsActiveConditionals ?? new List <PropertyConditional>(); foreach (XAttribute attribute in subElement.Attributes()) { if (PropertyConditional.IsValid(attribute)) { IsActiveConditionals.Add(new PropertyConditional(attribute)); } } break; case "requireditem": case "requireditems": SetRequiredItems(subElement); break; case "requiredskill": case "requiredskills": if (subElement.Attribute("name") != null) { DebugConsole.ThrowError("Error in item config \"" + item.ConfigFile + "\" - skill requirement in component " + GetType().ToString() + " should use a skill identifier instead of the name of the skill."); continue; } string skillIdentifier = subElement.GetAttributeString("identifier", ""); requiredSkills.Add(new Skill(skillIdentifier, subElement.GetAttributeInt("level", 0))); break; case "statuseffect": var statusEffect = StatusEffect.Load(subElement, item.Name); if (statusEffectLists == null) { statusEffectLists = new Dictionary <ActionType, List <StatusEffect> >(); } List <StatusEffect> effectList; if (!statusEffectLists.TryGetValue(statusEffect.type, out effectList)) { effectList = new List <StatusEffect>(); statusEffectLists.Add(statusEffect.type, effectList); } effectList.Add(statusEffect); break; default: if (LoadElemProjSpecific(subElement)) { break; } ItemComponent ic = Load(subElement, item, item.ConfigFile, false); if (ic == null) { break; } ic.Parent = this; ic.IsActive = isActive; OnActiveStateChanged += ic.SetActiveState; item.AddComponent(ic); break; } } }
public ServerSettings(NetworkMember networkMember, string serverName, int port, int queryPort, int maxPlayers, bool isPublic, bool enableUPnP) { ServerLog = new ServerLog(serverName); Voting = new Voting(); Whitelist = new WhiteList(); BanList = new BanList(); ExtraCargo = new Dictionary <ItemPrefab, int>(); PermissionPreset.LoadAll(PermissionPresetFile); InitProjSpecific(); ServerName = serverName; Port = port; QueryPort = queryPort; EnableUPnP = enableUPnP; MaxPlayers = maxPlayers; IsPublic = isPublic; netProperties = new Dictionary <UInt32, NetPropertyData>(); using (MD5 md5 = MD5.Create()) { var saveProperties = SerializableProperty.GetProperties <Serialize>(this); foreach (var property in saveProperties) { object value = property.GetValue(this); if (value == null) { continue; } string typeName = SerializableProperty.GetSupportedTypeName(value.GetType()); if (typeName != null || property.PropertyType.IsEnum) { NetPropertyData netPropertyData = new NetPropertyData(this, property, typeName); UInt32 key = ToolBox.StringToUInt32Hash(property.Name, md5); if (netProperties.ContainsKey(key)) { throw new Exception("Hashing collision in ServerSettings.netProperties: " + netProperties[key] + " has same key as " + property.Name + " (" + key.ToString() + ")"); } netProperties.Add(key, netPropertyData); } } var karmaProperties = SerializableProperty.GetProperties <Serialize>(networkMember.KarmaManager); foreach (var property in karmaProperties) { object value = property.GetValue(networkMember.KarmaManager); if (value == null) { continue; } string typeName = SerializableProperty.GetSupportedTypeName(value.GetType()); if (typeName != null || property.PropertyType.IsEnum) { NetPropertyData netPropertyData = new NetPropertyData(networkMember.KarmaManager, property, typeName); UInt32 key = ToolBox.StringToUInt32Hash(property.Name, md5); if (netProperties.ContainsKey(key)) { throw new Exception("Hashing collision in ServerSettings.netProperties: " + netProperties[key] + " has same key as " + property.Name + " (" + key.ToString() + ")"); } netProperties.Add(key, netPropertyData); } } } }
public ItemComponent(Item item, XElement element) { this.item = item; name = element.Name.ToString(); properties = SerializableProperty.GetProperties(this); //canBePicked = ToolBox.GetAttributeBool(element, "canbepicked", false); //canBeSelected = ToolBox.GetAttributeBool(element, "canbeselected", false); //msg = ToolBox.GetAttributeString(element, "msg", ""); requiredItems = new List <RelatedItem>(); requiredSkills = new List <Skill>(); #if CLIENT sounds = new Dictionary <ActionType, List <ItemSound> >(); #endif SelectKey = InputType.Select; try { string selectKeyStr = element.GetAttributeString("selectkey", "Select"); selectKeyStr = ToolBox.ConvertInputType(selectKeyStr); SelectKey = (InputType)Enum.Parse(typeof(InputType), selectKeyStr, true); } catch (Exception e) { DebugConsole.ThrowError("Invalid select key in " + element + "!", e); } PickKey = InputType.Select; try { string pickKeyStr = element.GetAttributeString("pickkey", "Select"); pickKeyStr = ToolBox.ConvertInputType(pickKeyStr); PickKey = (InputType)Enum.Parse(typeof(InputType), pickKeyStr, true); } catch (Exception e) { DebugConsole.ThrowError("Invalid pick key in " + element + "!", e); } properties = SerializableProperty.DeserializeProperties(this, element); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "requireditem": case "requireditems": RelatedItem ri = RelatedItem.Load(subElement); if (ri != null) { requiredItems.Add(ri); } break; case "requiredskill": case "requiredskills": string skillName = subElement.GetAttributeString("name", ""); requiredSkills.Add(new Skill(skillName, subElement.GetAttributeInt("level", 0))); break; case "statuseffect": var statusEffect = StatusEffect.Load(subElement); if (statusEffectLists == null) { statusEffectLists = new Dictionary <ActionType, List <StatusEffect> >(); } List <StatusEffect> effectList; if (!statusEffectLists.TryGetValue(statusEffect.type, out effectList)) { effectList = new List <StatusEffect>(); statusEffectLists.Add(statusEffect.type, effectList); } effectList.Add(statusEffect); break; default: if (LoadElemProjSpecific(subElement)) { break; } ItemComponent ic = Load(subElement, item, item.ConfigFile, false); if (ic == null) { break; } ic.Parent = this; item.components.Add(ic); break; } } }
public Limb(Ragdoll ragdoll, Character character, LimbParams limbParams) { this.ragdoll = ragdoll; this.character = character; this.Params = limbParams; wearingItems = new List <WearableSprite>(); dir = Direction.Right; body = new PhysicsBody(limbParams); type = limbParams.Type; if (limbParams.IgnoreCollisions) { body.CollisionCategories = Category.None; body.CollidesWith = Category.None; ignoreCollisions = true; } else { //limbs don't collide with each other body.CollisionCategories = Physics.CollisionCharacter; body.CollidesWith = Physics.CollisionAll & ~Physics.CollisionCharacter & ~Physics.CollisionItem & ~Physics.CollisionItemBlocking; } body.UserData = this; pullJoint = new FixedMouseJoint(body.FarseerBody, ConvertUnits.ToSimUnits(limbParams.PullPos * Scale)) { Enabled = false, //MaxForce = ((type == LimbType.LeftHand || type == LimbType.RightHand) ? 400.0f : 150.0f) * body.Mass // 150 or even 400 is too low if the joint is used for moving the character position from the mainlimb towards the collider position MaxForce = 1000 * Mass }; GameMain.World.Add(pullJoint); var element = limbParams.Element; body.BodyType = BodyType.Dynamic; foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "attack": attack = new Attack(subElement, (character == null ? "null" : character.Name) + ", limb " + type); if (attack.DamageRange <= 0) { switch (body.BodyShape) { case PhysicsBody.Shape.Circle: attack.DamageRange = body.radius; break; case PhysicsBody.Shape.Capsule: attack.DamageRange = body.height / 2 + body.radius; break; case PhysicsBody.Shape.Rectangle: attack.DamageRange = new Vector2(body.width / 2.0f, body.height / 2.0f).Length(); break; } attack.DamageRange = ConvertUnits.ToDisplayUnits(attack.DamageRange); } break; case "damagemodifier": DamageModifiers.Add(new DamageModifier(subElement, character.Name)); break; case "statuseffect": statusEffects.Add(StatusEffect.Load(subElement, Name)); break; } } SerializableProperties = SerializableProperty.GetProperties(this); InitProjSpecific(element); }
public ItemComponent(Item item, XElement element) { this.item = item; originalElement = element; name = element.Name.ToString(); SerializableProperties = SerializableProperty.GetProperties(this); requiredItems = new Dictionary <RelatedItem.RelationType, List <RelatedItem> >(); requiredSkills = new List <Skill>(); #if CLIENT sounds = new Dictionary <ActionType, List <ItemSound> >(); #endif SelectKey = InputType.Select; try { string selectKeyStr = element.GetAttributeString("selectkey", "Select"); selectKeyStr = ToolBox.ConvertInputType(selectKeyStr); SelectKey = (InputType)Enum.Parse(typeof(InputType), selectKeyStr, true); } catch (Exception e) { DebugConsole.ThrowError("Invalid select key in " + element + "!", e); } PickKey = InputType.Select; try { string pickKeyStr = element.GetAttributeString("pickkey", "Select"); pickKeyStr = ToolBox.ConvertInputType(pickKeyStr); PickKey = (InputType)Enum.Parse(typeof(InputType), pickKeyStr, true); } catch (Exception e) { DebugConsole.ThrowError("Invalid pick key in " + element + "!", e); } SerializableProperties = SerializableProperty.DeserializeProperties(this, element); ParseMsg(); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "requireditem": case "requireditems": RelatedItem ri = RelatedItem.Load(subElement, item.Name); if (ri != null) { if (!requiredItems.ContainsKey(ri.Type)) { requiredItems.Add(ri.Type, new List <RelatedItem>()); } requiredItems[ri.Type].Add(ri); } else { DebugConsole.ThrowError("Error in item config \"" + item.ConfigFile + "\" - component " + GetType().ToString() + " requires an item with no identifiers."); } break; case "requiredskill": case "requiredskills": if (subElement.Attribute("name") != null) { DebugConsole.ThrowError("Error in item config \"" + item.ConfigFile + "\" - skill requirement in component " + GetType().ToString() + " should use a skill identifier instead of the name of the skill."); continue; } string skillIdentifier = subElement.GetAttributeString("identifier", ""); requiredSkills.Add(new Skill(skillIdentifier, subElement.GetAttributeInt("level", 0))); break; case "statuseffect": var statusEffect = StatusEffect.Load(subElement, item.Name); if (statusEffectLists == null) { statusEffectLists = new Dictionary <ActionType, List <StatusEffect> >(); } List <StatusEffect> effectList; if (!statusEffectLists.TryGetValue(statusEffect.type, out effectList)) { effectList = new List <StatusEffect>(); statusEffectLists.Add(statusEffect.type, effectList); } effectList.Add(statusEffect); break; case "aitarget": AITarget = new AITarget(item, subElement) { Enabled = isActive }; break; default: if (LoadElemProjSpecific(subElement)) { break; } ItemComponent ic = Load(subElement, item, item.ConfigFile, false); if (ic == null) { break; } ic.Parent = this; item.AddComponent(ic); break; } } }