public void Hit(object message) { if (!(message is HitMessage)) { return; } // Tree has been hit (by an axe), so we create some wood cylinders the player can pick up ContainingWorld.RemoveEntity(thisEntity); // Gather wood from "real" trees only, not from cacti etc. if (treeType != TreeType.Birch) { return; } int numberOfWoodCylinders = 3 * (int)(amountOfWood + 1.0f); for (int i = 0; i < numberOfWoodCylinders; ++i) { ItemEntity itemEntity = new ItemEntity(new MaterialItem(TerrainResource.FromName("BirchWood"), MaterialShape.Cylinder, new vec3(0.2f, 0.7f, 0.2f))); ContainingWorld.AddEntity(itemEntity, mat4.Translate(Position + new vec3(0, 1 + i, 0))); } }
/// <summary> /// Adds a drone at the given position. /// Does not remove any drone from the inventory. /// </summary> public void AddDrone(vec3 position) { Drone d = new Drone(position + new vec3(0, 1, 0), this, DroneType.Chain); Drones.Add(d); // Add drone to the first constraint it can be added to. bool foundConstraint = false; foreach (var dc in DroneConstraints) { if (dc.IsAddable(d)) { // Drone is addable, i.e. the constraint contains a drone of the same type dc.AddDrone(d); foundConstraint = true; break; } } // If no constraint was found, we add a new one and add the drone to that. if (!foundConstraint) { DroneConstraints.Add(new DroneConstraint(d)); } // Add the drone as new entity. ContainingWorld.AddEntity(d, mat4.Translate(d.CurrentPosition), Network.GCManager.CurrentUserID); }
/// <summary> /// Drops an item. /// </summary> public void DropItem(Item item) { Item droppedItem = item.Clone(); Inventory.RemoveItem(item); ItemEntity itemEntity = new ItemEntity(droppedItem); ContainingWorld.AddEntity(itemEntity, mat4.Translate(Position + vec3.UnitY * 1f + CameraDirection * 1f)); itemEntity.ApplyImpulse(CameraDirection * 200f, new vec3(0, .3f, 0)); }
public void Interaction(object msg) { // Make sure we get the message type we are expecting. InteractionMessage interactionMsg = msg as InteractionMessage; if (interactionMsg == null) { return; } // Interacting with an item means picking it up. Answer by sending the item to the sender. interactionMsg.Sender[AddItemTrigger] |= new AddItemMessage(RepresentedItem); // And remove this entity. ContainingWorld.RemoveEntity(thisEntity); }
public void Interaction(object msg) { // Make sure we get the message type we are expecting. InteractionMessage interactionMsg = msg as InteractionMessage; if (interactionMsg == null) { return; } // Interacting with an item means picking it up. Answer by sending the item to the sender. interactionMsg.Sender[AddItemTrigger] |= new AddItemMessage(new ToolItem(ToolType.DroneChain)); // Remove drone from drone constraints. Owner.RemoveDrone(this); // And remove this entity. ContainingWorld.RemoveEntity(thisEntity); }