private void SpawnGatherables() { System.Random rand = MissionManager.instance.Rand; List <Item> unlockedGatherables = gatherablesToSpawn.FindAll(gatherable => gatherable.Unlocked); foreach (Transform spawner in gatherableSpawners) { // Debug.Log("spawning gatherables"); Item item; if (GameManager.instance != null && GameManager.instance.CurrentMission != null && !GameManager.instance.CurrentMission.completed && rand.NextDouble() < chosenGatherablesChance) { item = ItemManager.instance.itemsData.GetItemByName(GameManager.instance.CurrentMission.gatherableItemName); } else { item = unlockedGatherables[rand.Next(0, unlockedGatherables.Count)]; } Gatherable gatherable = Instantiate(prefabToSpawn, spawner.position, spawner.rotation); gatherable.Init(item); gatherable.transform.parent = room.transform; } }
private void OnCollisionEnter(Collision other) { GameObject otherGameObject = other.gameObject; Gatherable otherGatherable = other.gameObject.GetComponent <Gatherable>(); Transform otherTransform = otherGameObject.transform; Transform myTransform = gameObject.transform; string myParent = myTransform.parent == null ? "" : myTransform.parent.name; string otherParent = otherTransform.parent == null ? "" : otherTransform.parent.name; if (otherGatherable != null && otherGatherable.gatherType == this.gatherType && myParent != "GatherTarget" && otherParent != "GatherTarget") { float myVolume = myTransform.localScale.x * myTransform.localScale.y * myTransform.localScale.z; float otherVolume = otherTransform.localScale.x * otherTransform.localScale.y * otherTransform.localScale.z; if (myVolume >= otherVolume) { myTransform.localScale = new Vector3(myTransform.localScale.x + otherTransform.localScale.x, myTransform.localScale.y + otherTransform.localScale.y, myTransform.localScale.z + otherTransform.localScale.z); Destroy(otherGameObject); } } }
private string ReplaceFormatPlaceholders(string format, string input, Gatherable item) { var result = format.Replace("{Id}", item.ItemId.ToString()); result = result.Replace("{Name}", item.NameList[_language]); result = result.Replace("{Input}", input); return(result); }
static void Gatherable_StartInit_Post(Gatherable __instance) { #region quit if (!_gatherablesToggle) { return; } #endregion // Choose appropriate mode and timer ModSetting <ResetMode> mode = _gatheringMode; ModSetting <int> timer = _gatheringTimer; if (__instance.RequiredItem != null) { if (__instance.RequiredItem.ItemID == MINING_PICK_ID) { mode = _miningMode; timer = _miningTimer; } else if (__instance.RequiredItem.ItemID == FISHING_HARPOON_ID) { mode = _fishingMode; timer = _fishingTimer; } } // Calculat reset time based on mode float resetTime = 1 / 300f; // 500ms in realtime if (mode == ResetMode.Never) { resetTime = float.PositiveInfinity; } else if (mode == ResetMode.Timer) { resetTime = timer * TIME_UNIT; } // Execute foreach (var dropable in __instance.m_drops) { foreach (var dropTable in dropable.m_mainDropTables) { SimpleRandomChance dropAmount = dropTable.m_dropAmount; if (dropAmount.ChanceRegenDelay > 1) { dropAmount.m_chanceRegenDelay = resetTime; } foreach (var itemDropChance in dropTable.m_itemDrops) { if (itemDropChance.ChanceRegenDelay > 1) { itemDropChance.ChanceRegenDelay = resetTime; } } } } }
void OnCollisionEnter(Collision col) { //Debug.Log("Spaceship collided with : " + col.gameObject.name); if (col.gameObject.CompareTag("gatherable")) { //Debug.Log("Touched gatherable object !"); Gatherable g = col.gameObject.GetComponent <Gatherable>(); g.ActOnSpaceship(this); } }
private void drawHP(Gatherable sprite, SpriteBatch spriteBatch) { float HPgone = (float)sprite._HP / sprite._StartHP; Rectangle rect = new Rectangle((int)sprite._TopLeft.X, (int)sprite._TopLeft.Y - 10, (int)(64 * HPgone), 6); int green = (int)(HPgone * 255); int red = (255 - (int)(HPgone * 255)) + 100; Color col = new Color(red, green, 0); spriteBatch.Draw(_HpTex, rect, col); }
private void Start() { instance = this; gatherable = this.GetComponent <Gatherable>(); if (title == "" || title == null) { title = gameObject.name; } }
IEnumerator RotateTo(GameObject target, Vector3 point) { for (int i = 0; i < 20; i++) { GameObject.FindGameObjectWithTag("PlayerModel").GetComponent <Animator>().speed = 3; var targetRotation = Quaternion.LookRotation(target.transform.position - transform.position); // Smoothly rotate towards the target point. transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, 5 * Time.deltaTime); yield return(new WaitForEndOfFrame()); } if (target.GetComponent <Gatherable>() != null) { GetComponent <CharacterGatherController>().GatherResource(); if (target.GetComponent <Gatherable>() != null) { Gatherable gatherObject = target.GetComponent <Gatherable>(); if (gatherObject != null) { // Gatherable object found and clicked on! Do shit. if (gatherObject.resourceType == PublicEnums.ItemType.Stone) { Instantiate(GetComponent <CharacterGatherController>().StoneParticleSystem, point, Quaternion.identity); } else if (gatherObject.resourceType == PublicEnums.ItemType.Wood) { Instantiate(GetComponent <CharacterGatherController>().WoodParticleSystem, point, Quaternion.identity); } if (gatherObject.GetComponent <AudioSource>() != null) { gatherObject.GetComponent <AudioSource>().Play(); } } } target.GetComponent <Gatherable>().Gather(gameObject); } else if (target.GetComponent <Combatable>() != null) { RaycastHit hit; Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit); _combat.Attack(target.transform.gameObject); Instantiate(GetComponent <Combatable>().BloodParticles, point, Quaternion.identity); if (target.GetComponent <AudioSource>() != null) { target.GetComponent <AudioSource>().Play(); } } }
public GatherableType getBucketType() { if (this.getBucketCount() > 0) { Gatherable firstGatherable = gatherBucket[0].GetComponent <Gatherable>(); return(firstGatherable.gatherType); } else { return(GatherableType.All); } }
public MeshTile(int type, int tileX, int tileY, int gatherable, int gatherableHealth = 0, int gatherAmount = 0, int variant = 0, int biome = 0) { this.t = (Type)type; this.X = tileX; this.Y = tileY; this.g = (Gatherable)gatherable; this.h = gatherableHealth; this.a = gatherAmount; this.v = variant; this.b = (Biome)biome; }
private void SpawnMineables() { System.Random rand = MissionManager.instance.Rand; foreach (Transform spawner in mineableSpawners) { // Debug.Log("spawning gatherables"); var item = mineablesToSpawn[rand.Next(0, gatherablesToSpawn.Count)]; Gatherable gatherable = Instantiate(prefabToSpawn, spawner.position, spawner.rotation); gatherable.Init(item); gatherable.transform.parent = room.transform; } }
public static DM_Gatherable ParseGatherable(Gatherable gatherable) { var gatherableHolder = new DM_Gatherable { Name = gatherable.Name?.Trim(), ItemID = gatherable.ItemID }; if (At.GetField(gatherable as SelfFilledItemContainer, "m_drops") is List <Dropable> droppers) { if (droppers == null || droppers.Count < 1) { //SL.LogWarning("droppers is null or list count is 0!"); } else { foreach (Dropable dropper in droppers) { var dropableHolder = DM_DropTable.ParseDropable(dropper); gatherableHolder.DropTables.Add(dropableHolder.Name); } } } if (gatherableHolder.Name == "Fish") { gatherableHolder.Name = "Fishing Spot (" + gatherableHolder.DropTables[0] + ")"; } if (gatherableHolder.Name.Contains("vein")) { gatherableHolder.Name.Replace("vein", "Vein"); if (gatherableHolder.Name.Contains("Iron") || gatherableHolder.Name == "Palladium") { foreach (var table in gatherableHolder.DropTables) { if (table.Contains("Tourmaline")) { gatherableHolder.Name += " (Tourmaline)"; break; } } } } return(gatherableHolder); }
public GameObjects.ItemBundle GatherItem(Gatherable thing) { Random ran = new Random(); thing.GetHit(); if (thing._HP <= 0) { GameObjects.ItemBundle item = thing.GetGathered(); OnItemGathered(item.outputID.ToString()); return(item); } else { return(new GameObjects.ItemBundle()); } }
public GameObject GetGatherableFromType(Gatherable.GatherableType type) { GameObject correspondingGatherable = null; foreach (GameObject gatherablePrefab in gatherablePrefabs) { Gatherable g = gatherablePrefab.GetComponent <Gatherable>(); //Debug.Log("Searched Type: " + type.ToString() + " | Found Type: " + g.type.ToString()); if (g.type == type) { correspondingGatherable = gatherablePrefab; break; } } return(correspondingGatherable); }
public void blowFromBucket() { if (getBucketCount() > 0) { GameObject inHand = gatherBucket[0]; Gatherable inHandGScript = inHand.GetComponent <Gatherable>(); GatherableType inHandType = inHandGScript.gatherType; if (targets.Count > 0) { foreach (GameObject target in targets) { Gatherable targetGScript = target.GetComponent <Gatherable>(); GatherableType targetType = targetGScript.gatherType; if (targetType == inHandType) { float inHandScaleX = inHand.transform.localScale.x; float inHandScaleY = inHand.transform.localScale.y; float inHandScaleZ = inHand.transform.localScale.z; if (inHandScaleX > 0 && inHandScaleY > 0 && inHandScaleZ > 0) { inHand.transform.localScale = new Vector3(inHand.transform.localScale.x - 0.01f, inHand.transform.localScale.y - 0.01f, inHand.transform.localScale.z - 0.01f); target.transform.localScale = new Vector3(target.transform.localScale.x + 0.01f, target.transform.localScale.y + 0.01f, target.transform.localScale.z + 0.01f); } } else { generateBaseReturned(inHandType); } } } else { generateBaseReturned(inHandType); } } }
public void GatherResource() { RaycastHit rayHit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out rayHit)) { float distanceToResource = (rayHit.transform.position - transform.position).magnitude; //Debug.Log(distanceToResource); if (distanceToResource < MiningDistance) { Debug.DrawLine(transform.position, rayHit.transform.position); //Debug.Log(rayHit.GetType()); Gatherable gatherObject = rayHit.transform.GetComponent <Gatherable>(); } } }
public void Gather() { RaycastHit hit; Transform camT = PlayerManager.instance.playerCamera.transform; Ray shotRay = new Ray(camT.position, camT.forward); if (Physics.Raycast(shotRay, out hit, stats.miningDistance, GatherableLayer)) { Gatherable target = hit.collider.gameObject.GetComponent <Gatherable>(); if (!target && hit.collider.gameObject != null) { Debug.LogError("Tried mining object with no 'Gatherable' script"); } else { if (target.gatherableStats.gatherableType == selectedTool.toolType || target.gatherableStats.gatherableType < 0) { target.Damage(stats.miningDamage); //Debug.Log("Hit " + target.gameObject.name); } } } }
private void suckToBucket(GameObject targetObj) { Gatherable targetGScript = targetObj.GetComponent <Gatherable>(); GatherableType targetType = targetGScript.gatherType; GameObject gatheredObj; if (gatherBucket.Count == 0) { // Empty bucket, generate gatheredObj gatheredObj = generateBaseGathered(targetType); gatherBucket.Add(gatheredObj); gatheredObj.transform.parent = gameObject.transform; } else { gatheredObj = gatherBucket[0]; } float targetScaleX = targetObj.transform.localScale.x; float targetScaleY = targetObj.transform.localScale.y; float targetScaleZ = targetObj.transform.localScale.z; if (targetScaleX > 0 && targetScaleY > 0 && targetScaleZ > 0) { targetObj.transform.localScale = new Vector3(targetObj.transform.localScale.x - 0.01f, targetObj.transform.localScale.y - 0.01f, targetObj.transform.localScale.z - 0.01f); gatheredObj.transform.localScale = new Vector3(gatheredObj.transform.localScale.x + 0.01f, gatheredObj.transform.localScale.y + 0.01f, gatheredObj.transform.localScale.z + 0.01f); } }
/* * Changes the transforms of targets in the gatherer to that of the gatherPoint. * Takes in the gatherableType in the player's hand, or ALL, returning the first available * Returns the type of the object it has gathered. */ public void GatherTargets(GatherableType type) { if (targets.Count > 0) { GatherableType typeChoice = type; foreach (GameObject target in targets) { Gatherable targetGScript = target.GetComponent <Gatherable>(); GatherableType targetType = targetGScript.gatherType; Transform targetParent = target.transform.parent; // If gathering All types, then hand is empty, assign choice to first object type if (typeChoice.Equals(GatherableType.All)) { typeChoice = targetType; } if (targetType == typeChoice && (targetParent == null || (targetParent != null && targetParent.gameObject.name != "GatherPoint"))) { this.suckToBucket(target.gameObject); } } } }
//TODO: I really hate this, I don't want to have to make a class based on an enum public void AddObjectEntity(ObjectData data) { switch (data.type) { case ObjectType.Chest: Chest temp = new Chest(ScriptableObject.Instantiate(mCurrentMap.Data.chestType)); temp.Spawn(GetMapTilePosition(data.TilePosition)); break; case ObjectType.FallingRock: FallingRock temp2 = new FallingRock(Resources.Load("Prototypes/Entity/Objects/FallingRock") as EntityPrototype); temp2.Spawn(GetMapTilePosition(data.TilePosition)); break; case ObjectType.FlowerBed: FlowerBed temp3 = new FlowerBed(Resources.Load("Prototypes/Entity/Objects/FlowerBed") as EntityPrototype); temp3.Spawn(GetMapTilePosition(data.TilePosition)); break; case ObjectType.Tree: Tree temp4 = new Tree(Resources.Load("Prototypes/Entity/Objects/Tree") as EntityPrototype); temp4.Spawn(GetMapTilePosition(data.TilePosition)); break; case ObjectType.Medbay: MedicalBay temp5 = new MedicalBay(Resources.Load("Prototypes/Entity/Objects/Medbay") as EntityPrototype); temp5.Spawn(GetMapTilePosition(data.TilePosition)); break; case ObjectType.Door: if (mCurrentMap.mapType != MapType.BossMap) { Door temp6 = new Door(Resources.Load("Prototypes/Entity/Objects/Door") as DoorPrototype); if (mCurrentMap.Data.hasMiniboss) { temp6.locked = true; } temp6.Spawn(GetMapTilePosition(data.TilePosition)); } break; case ObjectType.NavSystem: NavSystem temp7 = new NavSystem(Resources.Load("Prototypes/Entity/Objects/NavSystem") as EntityPrototype); temp7.Spawn(GetMapTilePosition(data.TilePosition)); break; case ObjectType.BouncePad: BouncePad temp8 = new BouncePad(Resources.Load("Prototypes/Entity/Objects/BouncePad") as EntityPrototype); temp8.Spawn(GetMapTilePosition(data.TilePosition)); break; case ObjectType.Spikes: Spikes temp9 = new Spikes(Resources.Load("Prototypes/Entity/Objects/Spikes") as EntityPrototype); temp9.Spawn(GetMapTilePosition(data.TilePosition)); break; case ObjectType.Iceblock: Iceblock temp10 = new Iceblock(Resources.Load("Prototypes/Entity/Objects/Iceblock") as EntityPrototype); temp10.Spawn(GetMapTilePosition(data.TilePosition)); break; case ObjectType.AnalysisCom: AnalysisCom temp11 = new AnalysisCom(Resources.Load("Prototypes/Entity/Objects/AnalysisCom") as EntityPrototype); temp11.Spawn(GetMapTilePosition(data.TilePosition)); break; case ObjectType.Item: if (data is ItemObjectData itemData) { ItemObject temp12 = new ItemObject(ItemDatabase.GetItem(itemData.itemType), Resources.Load("Prototypes/Entity/Objects/ItemObject") as EntityPrototype); temp12.Spawn(GetMapTilePosition(data.TilePosition)); } break; case ObjectType.SmallGatherable: Gatherable temp13 = new Gatherable(Resources.Load("Prototypes/Entity/Objects/Gatherables/Small Blue Vein") as GatherablePrototype); temp13.Spawn(GetMapTilePosition(data.TilePosition)); break; case ObjectType.LargeGatherable: Gatherable temp14 = new Gatherable(Resources.Load("Prototypes/Entity/Objects/Gatherables/Large Blue Vein") as GatherablePrototype); temp14.Spawn(GetMapTilePosition(data.TilePosition)); break; case ObjectType.SaveMachine: SaveMachine temp15 = new SaveMachine(Resources.Load("Prototypes/Entity/Objects/SaveMachine") as EntityPrototype); temp15.Spawn(GetMapTilePosition(data.TilePosition)); break; case ObjectType.BreakableTile: BreakableTile temp16 = new BreakableTile(Resources.Load("Prototypes/Entity/Objects/BreakableTile") as EntityPrototype); temp16.Spawn(GetMapTilePosition(data.TilePosition)); break; case ObjectType.PracticeBot: PracticeBot temp17 = new PracticeBot(Resources.Load("Prototypes/Entity/Objects/PracticeBot") as EntityPrototype); temp17.Spawn(GetMapTilePosition(data.TilePosition)); break; case ObjectType.ShipTeleporter: ShipTeleporter temp18 = new ShipTeleporter(Resources.Load("Prototypes/Entity/Objects/ShipTeleporter") as EntityPrototype); temp18.Spawn(GetMapTilePosition(data.TilePosition)); break; case ObjectType.MovingPlatform: MovingPlatform temp19 = new MovingPlatform(Resources.Load("Prototypes/Entity/Objects/MovingPlatform") as EntityPrototype); temp19.Spawn(GetMapTilePosition(data.TilePosition)); break; } }