public ItemPickupEvent(CollectibleEntity collectibleEntity, BaseEntity.RPCMessage msg, Item item) { Entity = collectibleEntity; RPCMessage = msg; Player = Server.GetPlayer(msg.player); Item = new InvItem(item); }
public ItemPickupEvent(CollectibleEntity ce, BaseEntity.RPCMessage msg, Item i) { _entity = ce; _msg = msg; _player = Server.GetPlayer(msg.player); _item = new InvItem(i); }
public override bool WantsToEat(BaseEntity best) { if (best.HasTrait(BaseEntity.TraitFlag.Alive)) { return(false); } if (best.HasTrait(BaseEntity.TraitFlag.Meat)) { return(false); } CollectibleEntity collectibleEntity = best as CollectibleEntity; if (collectibleEntity != null) { ItemAmount[] itemAmountArray = collectibleEntity.itemList; for (int i = 0; i < (int)itemAmountArray.Length; i++) { if (itemAmountArray[i].itemDef.category == ItemCategory.Food) { return(true); } } } return(base.WantsToEat(best)); }
private void OnCollectiblePickup(Item item, BasePlayer player, CollectibleEntity entity) { if (item == null || player == null) { return; } LevelHandler(player, item, SkillList.acquiring); }
public static void Create() { CollectibleEntity asset = ScriptableObject.CreateInstance <CollectibleEntity>(); AssetDatabase.CreateAsset(asset, "Assets/_project/_data/NewCollectible.asset"); AssetDatabase.SaveAssets(); EditorUtility.FocusProjectWindow(); Selection.activeObject = asset; }
public virtual void EatNearbyFood() { if (UnityEngine.Time.time < nextEatTime) { return; } float num = StaminaCoreFraction(); nextEatTime = UnityEngine.Time.time + UnityEngine.Random.Range(2f, 3f) + Mathf.InverseLerp(0.5f, 1f, num) * 4f; if (num >= 1f) { return; } List <BaseEntity> obj = Facepunch.Pool.GetList <BaseEntity>(); Vis.Entities(base.transform.position + base.transform.forward * 1.5f, 2f, obj, 67109377); obj.Sort((BaseEntity a, BaseEntity b) => (b is DroppedItem).CompareTo(a is DroppedItem)); foreach (BaseEntity item in obj) { if (item.isClient) { continue; } DroppedItem droppedItem = item as DroppedItem; if ((bool)droppedItem && droppedItem.item != null && droppedItem.item.info.category == ItemCategory.Food) { ItemModConsumable component = droppedItem.item.info.GetComponent <ItemModConsumable>(); if ((bool)component) { ReplenishFromFood(component); droppedItem.item.UseItem(); if (droppedItem.item.amount <= 0) { droppedItem.Kill(); } break; } } CollectibleEntity collectibleEntity = item as CollectibleEntity; if ((bool)collectibleEntity && collectibleEntity.IsFood()) { collectibleEntity.DoPickup(null); break; } GrowableEntity growableEntity = item as GrowableEntity; if ((bool)growableEntity && growableEntity.CanPick()) { growableEntity.PickFruit(null); break; } } Facepunch.Pool.FreeList(ref obj); }
void OnCollectiblePickup(Item item, BasePlayer player, CollectibleEntity entity) { var ent = entity.GetEntity(); if (ent != null) { if (resourceCache.Contains(ent)) { InitiateRefresh(ent); resourceCache.Remove(ent); } } }
public static bool OnEntity(Entity entity) { var ent = BaseNetworkable.Get(entity.baseNetworkable.uid); if (ent != null) { ent.OnEntityUpdate(entity); return(ent.OnEntity(entity)); } var prefabId = entity.baseNetworkable.prefabID; if (prefabId == (UInt32)EPrefabUID.BasePlayer) { ent = new BasePlayer(); } else if (prefabId == (UInt32)EPrefabUID.OreBonus) { ent = new OreBonus(); } else if (entity.resource != null && Database.IsOreResource(prefabId)) { ent = new OreResource(); } else if (entity.heldEntity != null) { ent = new BaseHeldEntity(); } else if (OpCodes.IsStorage(entity.baseNetworkable.prefabID)) { ent = new StorageContainer(); } else if (Database.IsCollectible(prefabId)) { ent = new CollectibleEntity(); } else if (Database.IsBaseResource(prefabId)) { ent = new BaseResource(); } else if (entity.worldItem != null && Database.IsComponent(entity.worldItem.item.itemid)) { //new WorldItem(); } if (ent == null) { return(false); } ent.OnEntityCreate(entity); return(ent.OnEntity(entity)); }
void OnCollectiblePickup(Item item, BasePlayer player, CollectibleEntity entity) { if (player == null || player.inventory == null || !entity.PrefabName.Contains("hemp-collectable")) { return; } if (HasClaimed(player) || IsFull(player.inventory)) { return; } GiveItem(player); }
void OnCollectiblePickup(Item item, BasePlayer player, CollectibleEntity entity) { if (config.EnableGatherRate) { if (item.info.shortname == "hemp") { item.amount = ChangeGather(item.amount, gathermultiplier[item.info.shortname]); } else { item.amount = ChangeGather(item.amount, config.GatherRatePickups); } } }
void OnCollectiblePickup(Item item, BasePlayer player, CollectibleEntity entity) { if (item == null) { return; } if (player == null || !configData.ActiveChallengeTypes[CTypes.Plants.ToString()]) { return; } if (plantShortnames.Contains(item?.info?.shortname)) { AddPoints(player, CTypes.Plants, 1); } }
private void OnCollectiblePickup(Item item, BasePlayer player, CollectibleEntity entity) { if (item == null) { return; } if (player == null || player is NPCPlayer || !configData.ChallengeSettings[Challenges.PlantsGathered].Enabled) { return; } if (plantShortnames.Contains(item?.info?.shortname)) { AddPoints(player, Challenges.PlantsGathered, 1); } }
public override bool WantsToEat(BaseEntity best) { if (best.HasTrait(BaseEntity.TraitFlag.Alive) || best.HasTrait(BaseEntity.TraitFlag.Meat)) { return(false); } CollectibleEntity collectibleEntity = best as CollectibleEntity; if (Object.op_Inequality((Object)collectibleEntity, (Object)null)) { foreach (ItemAmount itemAmount in collectibleEntity.itemList) { if (itemAmount.itemDef.category == ItemCategory.Food) { return(true); } } } return(base.WantsToEat(best)); }
object OnCollectiblePickup(Item item, BasePlayer player, CollectibleEntity entity) { // Block for player who chopped down the tree... if (playerGathered.ContainsKey(player.userID)) { foreach (Stumps stump in playerGathered[player.userID]) { if (stump.netid == entity.net.ID) { TimeSpan sec = TimeSpan.FromSeconds(configData.Options.protectedMinutes * 60); if (DateTime.Now - stump.chopped < sec) { var endtime = stump.chopped + new TimeSpan(0, configData.Options.protectedMinutes, 0); var towait = endtime - DateTime.Now; var seconds = Math.Floor(towait.TotalSeconds); if (seconds < 60) { Message(player.IPlayer, "nogather1", seconds.ToString()); } else { Message(player.IPlayer, "nogather2", towait.Minutes.ToString()); } return(true); } else { playerGathered[player.userID].RemoveWhere((x) => x.netid == entity.net.ID); return(null); } } } } return(null); }
/// <summary> /// Called from <c>CollectibleEntity.Pickup(BaseEntity.RPCMessage)</c> . /// </summary> public static void On_ItemPickup(CollectibleEntity entity, BaseEntity.RPCMessage msg) { if (!msg.player.IsAlive() || !msg.player.CanInteract() || entity.itemList == null) return; foreach (ItemAmount itemAmount in entity.itemList) { Item item = ItemManager.Create(itemAmount.itemDef, (int)itemAmount.amount, 0); OnNext("On_ItemPickup", new ItemPickupEvent(entity, msg, item)); msg.player.GiveItem(item, BaseEntity.GiveItemReason.PickedUp); } entity.itemList = null; if (entity.pickupEffect.isValid) { Effect.server.Run(entity.pickupEffect.resourcePath, entity.transform.position, entity.transform.up, null, false); } entity.Kill(BaseNetworkable.DestroyMode.None); }
// On Collectible Pickup // Called when the player collects an item object OnCollectiblePickup(Item item, BasePlayer player, CollectibleEntity entity) { CreateLogEntry("on_player_gather.log", new ResidentGatheredItem(player, entity?.name, item)); return(null); }
private void OnGUI() { try { if (bDrawResources || bDrawCollectibles) { foreach (BaseNetworkable NetworkableObject in BaseNetworkable.clientEntities) { if (bDrawResources) { if (NetworkableObject is ResourceEntity) { ResourceEntity resource = NetworkableObject as ResourceEntity; if (resource != null) { if (resource.ShortPrefabName.Contains("ore")) { Vector3 vector = MainCamera.mainCamera.WorldToScreenPoint(resource.transform.position); if (vector.z > 0f) { int distance = (int)Vector3.Distance(LocalPlayer.Entity.transform.position, resource.transform.position); if (distance <= iDrawDistanceLoot) { vector.x += 3f; vector.y = Screen.height - (vector.y + 1f); Renderer.DrawString(new Vector2(vector.x, vector.y), string.Format("{0} [{1}m]", resource.ShortPrefabName.Replace(".prefab", "") .Replace("_deployed", ""), distance), cResourceColor, true, 12, true); } } } } } } if (bDrawCollectibles) { if (NetworkableObject is CollectibleEntity) { CollectibleEntity collectible = NetworkableObject as CollectibleEntity; if (collectible != null) { Vector3 vector = MainCamera.mainCamera.WorldToScreenPoint(collectible.transform.position); if (vector.z > 0f) { int distance = (int)Vector3.Distance(LocalPlayer.Entity.transform.position, collectible.transform.position); if (distance <= iDrawDistanceLoot) { vector.x += 3f; vector.y = Screen.height - (vector.y + 1f); Renderer.DrawString(new Vector2(vector.x, vector.y), //string.Format("{0} [{1}m]", // collectible.ShortPrefabName.Replace(".prefab", "") // .Replace("_deployed", ""), distance), string.Format("{0} [{1}m]", collectible.itemName.english, distance), cCollectibleColor, true, 12, true); } } } } } } } } catch (Exception e) { Debug.LogException(e); } }
public void EatNearbyFood() { if (Time.time < this.nextEatTime) { return; } float single = this.StaminaCoreFraction(); this.nextEatTime = Time.time + UnityEngine.Random.Range(2f, 3f) + Mathf.InverseLerp(0.5f, 1f, single) * 4f; if (single >= 1f) { return; } List <BaseEntity> list = Pool.GetList <BaseEntity>(); Vis.Entities <BaseEntity>(base.transform.position + (base.transform.forward * 1.5f), 2f, list, 67109377, QueryTriggerInteraction.Collide); list.Sort((BaseEntity a, BaseEntity b) => b is DroppedItem.CompareTo(a is DroppedItem)); foreach (BaseEntity baseEntity in list) { if (baseEntity.isClient) { continue; } DroppedItem droppedItem = baseEntity as DroppedItem; if (droppedItem && droppedItem.item != null && droppedItem.item.info.category == ItemCategory.Food) { ItemModConsumable component = droppedItem.item.info.GetComponent <ItemModConsumable>(); if (component) { base.ClientRPC(null, "Eat"); this.lastEatTime = Time.time; float ifType = component.GetIfType(MetabolismAttribute.Type.Calories); float ifType1 = component.GetIfType(MetabolismAttribute.Type.Hydration); float single1 = component.GetIfType(MetabolismAttribute.Type.Health) + component.GetIfType(MetabolismAttribute.Type.HealthOverTime); this.ReplenishStaminaCore(ifType, ifType1); this.Heal(single1 * 2f); droppedItem.item.UseItem(1); if (droppedItem.item.amount > 0) { break; } droppedItem.Kill(BaseNetworkable.DestroyMode.None); Pool.FreeList <BaseEntity>(ref list); return; } } CollectibleEntity collectibleEntity = baseEntity as CollectibleEntity; if (!collectibleEntity || !collectibleEntity.IsFood()) { PlantEntity plantEntity = baseEntity as PlantEntity; if (!plantEntity || !plantEntity.CanPick()) { continue; } plantEntity.PickFruit(null); Pool.FreeList <BaseEntity>(ref list); return; } else { collectibleEntity.DoPickup(null); Pool.FreeList <BaseEntity>(ref list); return; } } Pool.FreeList <BaseEntity>(ref list); }
public static void Pickup(CollectibleEntity ce, BaseEntity.RPCMessage msg, Item i) { OnItemPickup.OnNext(new ItemPickupEvent(ce, msg, i)); }
public void Merge(CollectibleEntity c) { throw new NotImplementedException(); }
public static void On_ItemPickup(CollectibleEntity ce, BaseEntity.RPCMessage msg, Item i) { OnNext("On_ItemPickup", new ItemPickupEvent(ce, msg, i)); }