public override void OnAttached( AbstractEntity entity ) { bool needAllContacts = entity.HasBool("need_all_contacts") && entity.GetBool("need_all_contacts"); string modelName = entity.GetString(CommonNames.Mesh); VolumeCollection[] collisionVolumes = Game.Instance.ContentManager.Load <MagmaModel>(modelName).VolumeCollection; if (collisionVolumes == null) { throw new System.Exception(string.Format("model {0} has no collision volumes!", modelName)); } if (entity.HasString("bv_type")) { string bv_type = entity.GetString("bv_type"); if (bv_type == "cylinder") { object[] bvCylinders = new object[collisionVolumes.Length]; for (int i = 0; i < collisionVolumes.Length; ++i) { bvCylinders[i] = collisionVolumes[i].GetVolume(VolumeType.Cylinder3); } Game.Instance.Simulation.CollisionManager.AddCylinderCollisionEntity(entity as Entity, this, bvCylinders, needAllContacts); } else if (bv_type == "alignedbox3tree") { object[] bvTrees = new object[collisionVolumes.Length]; for (int i = 0; i < collisionVolumes.Length; ++i) { bvTrees[i] = collisionVolumes[i].GetVolume(VolumeType.AlignedBox3Tree); } Game.Instance.Simulation.CollisionManager.AddAlignedBox3TreeCollisionEntity(entity as Entity, this, bvTrees, needAllContacts); } else if (bv_type == "sphere") { object[] bvSpheres = new object[collisionVolumes.Length]; for (int i = 0; i < collisionVolumes.Length; ++i) { bvSpheres[i] = collisionVolumes[i].GetVolume(VolumeType.Sphere3); } Game.Instance.Simulation.CollisionManager.AddSphereCollisionEntity(entity as Entity, this, bvSpheres, needAllContacts); } else if (bv_type == "alignedbox3") { AlignedBox3[] bvBoxes = new AlignedBox3[collisionVolumes.Length]; for (int i = 0; i < collisionVolumes.Length; ++i) { bvBoxes[i] = (AlignedBox3)collisionVolumes[i].GetVolume(VolumeType.AlignedBox3); } throw new System.Exception("bounding boxes not yet supported!"); } } }
public override void OnAttached(AbstractEntity entity) { Debug.Assert(entity.HasVector3(CommonNames.Position)); this.island = entity as Entity; this.constants = Game.Instance.Simulation.EntityManager["island_constants"]; this.playerConstants = Game.Instance.Simulation.EntityManager["player_constants"]; if (!entity.HasAttribute(CommonNames.MaxHealth)) { entity.AddFloatAttribute(CommonNames.MaxHealth, (entity.GetVector3(CommonNames.Scale).Length() * constants.GetFloat("scale_health_multiplier"))); } entity.AddFloatAttribute(CommonNames.Health, entity.GetFloat(CommonNames.MaxHealth)); hasFixedMovementPath = entity.GetBool("fixed"); entity.AddVector3Attribute("repulsion_velocity", Vector3.Zero); entity.AddVector3Attribute("pushback_velocity", Vector3.Zero); entity.AddVector3Attribute("repositioning_velocity", Vector3.Zero); entity.AddStringAttribute("repulsed_by", ""); entity.AddIntAttribute("players_on_island", 0); entity.AddIntAttribute("players_targeting_island", 0); // approximation of island's radius and height Vector3 scale = island.GetVector3(CommonNames.Scale); entity.AddFloatAttribute("height", scale.Y); scale.Y = 0; entity.AddFloatAttribute("radius", scale.Length()); (entity as Entity).OnUpdate += OnUpdate; entity.GetProperty <CollisionProperty>("collision").OnContact += CollisionHandler; // ((Vector3Attribute)entity.GetAttribute("repulsion_velocity")).ValueChanged += RepulsionChangeHandler; entity.GetAttribute <StringAttribute>("repulsed_by").ValueChanged += RepulsedByChangeHandler; entity.GetAttribute <IntAttribute>("players_on_island").ValueChanged += PlayersOnIslandChangeHandler; originalPosition = entity.GetVector3(CommonNames.Position); }