// Update is called once per frame void Update() { if (Input.GetButtonDown("Fire1") || Input.GetButtonDown("Fire2")) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { GameObject mob = (Input.GetButtonDown("Fire1") ? mob2 : (Input.GetButtonDown("Fire2") ? mob1 : null)); GameObject g = Instantiate(mob, new Vector3(hit.point.x, hit.point.y, 0f), transform.rotation); GameObject hp = Instantiate(mobHealthBar, new Vector3(hit.point.x, hit.point.y, 0f), transform.rotation); hp.transform.SetParent(mobHealthCanvas.transform, false); Room r = hit.transform.gameObject.GetComponent <RoomSprite>().room; BaseMob bm = g.GetComponent <BaseMob>(); bm.currentRoom = r; bm.pickTarget(); bm.player = (Input.GetButtonDown("Fire1") ? false : (Input.GetButtonDown("Fire2") ? true : false)); bm.healthSlider = hp; bm.damageImage = bm.healthSlider.gameObject.transform.GetComponentInChildren <Image>(); bm.updateHealthBarPosition(); r.mobs.Add(g); } } }
// Check predator too close public virtual void checkPredatorTooClose(int predatorType) { MobManager manager = attachedMob.manager; // Loop over all entities to find closest predator foreach (int uniqueID in attachedMob.manager.getAllIDs()) { // Check that the mobDict actually contains that mob ID if (manager.mobDict.ContainsKey(uniqueID)) { BaseMob otherMob = manager.mobDict[uniqueID]; // Check if the otherMob is a predator for a given class if (otherMob.mobType == predatorType) { // Distance to predator double distance = Vector2.Distance(attachedMob.rigidBody.position, otherMob.rigidBody.position); if (distance < predatorKillRadius) { attachedMob.OnDeath(); manager.UnRegisterMob(attachedMob); return; } } } else { Debug.Log("uniqueID not in list: " + uniqueID.ToString()); } } }
// Use this for initialization void Start() { float frameCD = 5f; if (ScoreManager.StillPlaying()) { //Debug.Log("3"); /*ScoreManager sm = GameObject.FindObjectOfType<ScoreManager>(); * //Debug.Log("4"); * if (sm.money < itemFramesCost) * { * Debug.Log("Not enough money!"); * return; * } * * sm.ChangeBalance(-1 * itemFramesCost);*/ Griefer[] griefers = GameObject.FindObjectsOfType <Griefer>(); foreach (Griefer griefer in griefers) { if (griefer.Vulnerable()) { griefer.SetFrameCD(frameCD); } } BaseMob mob = this.GetComponent <BaseMob>(); mob.Remove(); } }
/// <title>Saga.AddWaypoint</title> /// <code> /// Saga.AddWaypoint(cid, QuestID, StepId, State); /// </code> /// <description> /// Adds a waypoint to the quest list. /// (Note it will also activate the npc if it's not yet activated) /// </description> /// <example> /// function QUEST_STEP_2(cid) /// -- Talk to mischa /// local NPCIndex = 1000; /// local ret = Saga.GetNPCIndex(cid); /// /// Saga.AddWaypoint(cid, QuestID, NPCIndex, -12092, -6490, -8284, 1); /// if ret == NPCIndex then /// Saga.StepComplete(cid, QuestID, 102); /// else /// return -1; /// end /// /// Saga.ClearWaypoints(cid, QuestID); /// return 0; /// end /// </example> public static void AddWayPoint(uint cid, uint QID, uint stepid, byte substepid, uint npcType) { Character Character; if (LifeCycle.TryGetById(cid, out Character)) { //Substep - 1; substepid--; //Find the substep Predicate <Saga.Quests.Objectives.ObjectiveList.SubStep> FindSubstep = delegate(Saga.Quests.Objectives.ObjectiveList.SubStep objective) { return(objective.Quest == QID && objective.StepId == stepid && objective.SubStepId == substepid); }; Predicate <Saga.Quests.Objectives.ObjectiveList.Waypoint> FindWaypoint = delegate(Saga.Quests.Objectives.ObjectiveList.Waypoint objective) { return(objective.Quest == QID && objective.StepId == stepid && objective.NpcId == npcType); }; //Get substep list List <Saga.Quests.Objectives.ObjectiveList.SubStep> Substeps = Character.QuestObjectives.Substeps; //Add waypoint List <Saga.Quests.Objectives.ObjectiveList.Waypoint> Waypoints = Character.QuestObjectives.GuidancePoints; //Add substeps int index = Substeps.FindIndex(FindSubstep); if (index == -1) { int index2 = Waypoints.FindIndex(FindWaypoint); if (index2 == -1) { Substeps.Add(new Saga.Quests.Objectives.ObjectiveList.SubStep(substepid, false, 0, 1, QID, stepid)); Waypoints.Add(new Saga.Quests.Objectives.ObjectiveList.Waypoint(npcType, QID, stepid, substepid)); Regiontree tree = Character.currentzone.Regiontree; foreach (MapObject a in tree.SearchActors(Character, SearchFlags.Npcs)) { BaseMob mob = a as BaseMob; if (a.ModelId == npcType) { if (mob != null) { Common.Actions.UpdateIcon(Character, mob); } } } } } } }
static void Main(string[] args) { var baseMob = new BaseMob(); var vurdalakMob = new VurdalakMob(""); Console.ReadLine(); }
public static void UpdateIcon(Character target, BaseMob mob) { SMSG_ACTORUPDATEICON spkt = new SMSG_ACTORUPDATEICON(); spkt.ActorID = mob.id; spkt.SessionId = target.id; spkt.Icon = (byte)mob.ComputeIcon(target); target.client.Send((byte[])spkt); }
public void addMob(BaseMob mob) { if (mobsNo < mobContainer.Length) { mobContainer[mobsNo] = mob; mobContainer[mobsNo].setPath(path); mobContainer[mobsNo].setRepeat(1); mobsNo++; } }
public void SelectTowerType(int prefab) { //Debug.Log("clicked"); if (ScoreManager.StillPlaying()) { if ((prefab >= 0) && (prefab < mobsArray.Length)) { if (GetComponent <ScoreManager>().money >= mobsArray[prefab].GetComponent <BaseMob>().cost) { if (cooldowns[prefab] <= 0) { selectedImage.sprite = sprites[prefab]; EnableSelect(false); selectedPrefab = mobsArray[prefab]; } else { GameObject.FindObjectOfType <ScoreManager>().ChangeCenterText("Patience is virtue!"); } } else { GetComponent <ScoreManager>().ChangeCenterText("Not enough money!"); //Debug.Log(GameObject.FindObjectOfType<ScoreManager>().money + " " + mobsArray[prefab].GetComponent<BaseMob>().cost); } } else { if (selectedInstance != null) { switch (selectedInstance.id) { case 0: selectedInstance.GetComponent <Skeleton>().RangeGO().SetActive(false); break; case 2: selectedInstance.GetComponent <Witch>().RangeGO().SetActive(false); break; case 5: selectedInstance.GetComponent <Skeleton>().RangeGO().SetActive(false); break; } } selectedPrefab = null; selectedInstance = null; upgradeButton.gameObject.SetActive(false); sellButton.gameObject.SetActive(false); EnableSelect(true); } } }
// Check if another creature is close to mate public virtual (Vector2?, int?) getClosestMatingPartner() { // Check that the timeframe after last mating is enough if (!attachedMob.wantsToMate()) { return(null, null); } double minFoodDistance = double.MaxValue; Vector2 closestFoodPosition = Vector2.zero; int closestFoodID = -1; // Set initial closestFoodID to -1 (invalid, all IDs are chosen positive in the manager) MobManager manager = attachedMob.manager; // Loop over all entities to find closest food foreach (int uniqueID in attachedMob.manager.getAllIDs()) { // Check that the mobDict actually contains that mob ID if (manager.mobDict.ContainsKey(uniqueID)) { BaseMob otherMob = manager.mobDict[uniqueID]; // Check if the otherMob is of the same type and not itself if ((otherMob.mobType == attachedMob.mobType) && (otherMob.managerID != attachedMob.managerID) && (otherMob.wantsToMate())) { // Distance to food item double distance = Vector2.Distance(attachedMob.rigidBody.position, otherMob.rigidBody.position); // If distance is closer than the last distance saved, update the closest distance and ID if ((distance < minFoodDistance) & (distance < attachedMob.getSeekingFoodRadius())) { minFoodDistance = distance; closestFoodID = uniqueID; closestFoodPosition = otherMob.rigidBody.position; } } } else { Debug.Log("uniqueID not in list: " + uniqueID.ToString()); } } // If a valid food is encountered, return its ID and direction if (closestFoodID != -1) { Vector2 direction = new Vector2(closestFoodPosition.x - attachedMob.rigidBody.position.x, closestFoodPosition.y - attachedMob.rigidBody.position.y); return(direction, closestFoodID); } return(null, null); }
public static bool UserTalktoTarget(uint NpcId, Character Target, QuestBase Quest) { try { Quest.CheckQuest(Target); if (true) { /* * //Predicate to remove the activated npc * Predicate<ObjectiveList.Activation> FindActivatedNpc = * delegate(ObjectiveList.Activation objective) * { * return objective.NpcId == NpcId && objective.Quest == Quest.QuestId; * }; */ //Target.QuestObjectives.ActivatedNpc.RemoveAll(FindActivatedNpc); /* * MapObject myObject = Target.currentzone.Regiontree.SearchActor(IsNpc, Target, SearchFlags.Npcs); * if (myObject != null) * { * BaseMob temp = myObject as BaseMob; * }*/ /**/ Regiontree tree = Target.currentzone.Regiontree; foreach (MapObject a in tree.SearchActors(Target, SearchFlags.Npcs)) { if (a.ModelId == NpcId) { BaseMob mob = a as BaseMob; if (mob != null) { Common.Actions.UpdateIcon(Target, mob); } } } return(true); } } catch (QuestFailedException) { //Do nothing here return(false); } }
public void SelectInstance(BaseMob instance) { selectedInstance = instance; selectedImage.sprite = sprites[instance.id]; EnableSelect(false); sellText.text = "Sell (" + (int)(selectedInstance.Spent() / 2.0) + ")"; sellButton.gameObject.SetActive(true); if (selectedInstance.Level() < 2) { upgradeText.text = "Upgrade (" + selectedInstance.upgradeCost + ")"; upgradeButton.gameObject.SetActive(true); } }
public static void UpdateNpcIcons(Character target) { foreach (MapObject myObject in target.currentzone.GetObjectsInRegionalRange(target)) { if (MapObject.IsNotMonster(myObject) && target.currentzone.IsInSightRangeBySquare(target.Position, myObject.Position)) { BaseMob temp = myObject as BaseMob; if (temp != null) { Common.Actions.UpdateIcon(target, temp); } } } }
void spawn() { int mobType = Random.Range(0, mobs.Length - 1); GameObject mob = Instantiate(mobs[mobType]); mob.transform.position = this.transform.position; BaseMob bm = mob.GetComponent <BaseMob>(); bm.currentRoom = parentRoom; int roomIndex = Random.Range(0, parentRoom.AdjacentRooms.Count); if (roomIndex >= 0 && roomIndex < parentRoom.AdjacentRooms.Count) { bm.walkTarget = parentRoom.AdjacentRooms[roomIndex].spawner; } }
// Check if it's mating public virtual void checkIfMating() { MobManager manager = attachedMob.manager; // Loop over all entities to find closest predator foreach (int uniqueID in attachedMob.manager.getAllIDs()) { // Check that the mobDict actually contains that mob ID if (manager.mobDict.ContainsKey(uniqueID)) { BaseMob otherMob = manager.mobDict[uniqueID]; // Check if the otherMob is a predator for a given class if ((otherMob.mobType == attachedMob.mobType) && (otherMob.managerID != attachedMob.managerID)) { // Distance to predator double distance = Vector2.Distance(attachedMob.rigidBody.position, otherMob.rigidBody.position); if ((distance < matingRadius) && (otherMob.wantsToMate() && attachedMob.wantsToMate())) { attachedMob.timeSinceLastMating = 0; otherMob.timeSinceLastMating = 0; Debug.Log("SHOULD MATE"); // Compute mating position as the average between the two positions float positionX = (float)(attachedMob.rigidBody.position.x + otherMob.rigidBody.position.x) / 2.0f; float positionY = (float)(attachedMob.rigidBody.position.y + otherMob.rigidBody.position.y) / 2.0f; // Save the child object GameObject child = GameObject.Instantiate(attachedMob.mobPrefabChild, new Vector2(positionX, positionY), Quaternion.identity); // Childs do not want to mate child.GetComponent <BaseMob>().timeSinceLastMating = 0.0; return; } } } else { Debug.Log("uniqueID not in list: " + uniqueID.ToString()); } } }
// Update is called once per frame void Update() { if (ScoreManager.Timer()) { lifeRemaining -= Time.deltaTime; diamondCDRemaining -= Time.deltaTime; if (diamondCDRemaining <= 0) { Instantiate(diamond, this.transform.position, this.transform.rotation); diamondCDRemaining = diamondCD; } if (lifeRemaining <= 0) { BaseMob mob = this.GetComponent <BaseMob>(); mob.Remove(); } } }
void OnMouseUp() { if (!occupied) { //Debug.Log("1"); BuildingManager bm = GameObject.FindObjectOfType <BuildingManager>(); //Debug.Log("2"); /*if (tileType == 0) * { * selectedTower = bm.selectedTower; * }*/ if (bm.SelectedTower() == null) { bm.SelectTowerType(-1); return; } int id = bm.SelectedTower().GetComponent <BaseMob>().id; switch (tileType) { case 0: if ((id != 1) && (id != 5) && (id != 8)) { selectedTower = bm.SelectedTower(); } else { GameObject.FindObjectOfType <ScoreManager>().ChangeCenterText("Wrong block!"); return; } break; case 1: if ((id == 8) || (id == 4) || (id == 6)) { selectedTower = bm.SelectedTower(); } else { GameObject.FindObjectOfType <ScoreManager>().ChangeCenterText("Wrong block!"); return; } break; case 2: if ((id == 1) || (id == 4) || (id == 6)) { selectedTower = bm.SelectedTower(); } else { GameObject.FindObjectOfType <ScoreManager>().ChangeCenterText("Wrong block!"); return; } break; case 3: if ((id == 5) || (id == 4) || (id == 6)) { selectedTower = bm.SelectedTower(); } else { GameObject.FindObjectOfType <ScoreManager>().ChangeCenterText("Wrong block!"); return; } break; } if ((selectedTower != null) && ScoreManager.StillPlaying()) { //Debug.Log("3"); ScoreManager sm = GameObject.FindObjectOfType <ScoreManager>(); //Debug.Log("4"); if (sm.money < selectedTower.GetComponent <BaseMob>().cost) { GameObject.FindObjectOfType <ScoreManager>().ChangeCenterText("Not enough money!"); return; } sm.ChangeBalance(selectedTower.GetComponent <BaseMob>().cost *(-1)); GameObject mobGO = (GameObject)Instantiate(selectedTower, this.transform.position, this.transform.rotation); BaseMob mob = mobGO.GetComponent <BaseMob>(); mob.SetSpot(this); bm.StartCooldown(mob.id, mob.buyCooldown); //Destroy(transform.parent.gameObject); bm.SelectTowerType(-1); occupied = true; } } }
public void spawnNewMob(BaseMob mob) { addMob(mob); }
public static void InvalidateQuest(QuestBase Quest, Character Target) { List <ObjectiveList.Waypoint> removedpoints = new List <ObjectiveList.Waypoint>(); Predicate <ObjectiveList.Elimination> FindElimintation = delegate(ObjectiveList.Elimination Objective) { return(Objective.Quest == Quest.QuestId); }; Predicate <ObjectiveList.Loot> FindLootObjective = delegate(ObjectiveList.Loot Objective) { return(Objective.Quest == Quest.QuestId); }; Predicate <ObjectiveList.Position> FindPoint = delegate(ObjectiveList.Position Objective) { return(Objective.Quest == Quest.QuestId); }; Predicate <ObjectiveList.Activation> ActivatedNpc = delegate(ObjectiveList.Activation Objective) { return(Objective.Quest == Quest.QuestId); }; Predicate <ObjectiveList.SubStep> FindSubsteps = delegate(ObjectiveList.SubStep Objective) { return(Objective.Quest == Quest.QuestId); }; Predicate <ObjectiveList.Waypoint> FindGuidancePoints = delegate(ObjectiveList.Waypoint Objective) { bool isQuest = Objective.Quest == Quest.QuestId; if (isQuest) { removedpoints.Add(Objective); } return(isQuest); }; Predicate <ObjectiveList.Loot2> FindNonDiscardableItems = delegate(ObjectiveList.Loot2 objective) { return(objective.Quest == Quest.QuestId); }; Target.QuestObjectives.Elimintations.RemoveAll(FindElimintation); Target.QuestObjectives.ActivatedNpc.RemoveAll(ActivatedNpc); Target.QuestObjectives.LootObjectives.RemoveAll(FindLootObjective); Target.QuestObjectives.Points.RemoveAll(FindPoint); Target.QuestObjectives.Substeps.RemoveAll(FindSubsteps); Target.QuestObjectives.Steps.Remove(Quest.QuestId); Target.QuestObjectives.NonDiscardableItems.RemoveAll(FindNonDiscardableItems); Target.QuestObjectives.GuidancePoints.RemoveAll(FindGuidancePoints); foreach (ObjectiveList.Waypoint objective in removedpoints) { Regiontree tree = Target.currentzone.Regiontree; foreach (MapObject a in tree.SearchActors(Target, SearchFlags.Npcs)) { BaseMob mob = a as BaseMob; if (a.ModelId == objective.NpcId && mob != null) { Common.Actions.UpdateIcon(Target, mob); } } } }