//Loads level, including any enemies private void LoadLevel() { CombatDetails cd = CombatDetails.GetComponent <CombatDetails>(); //Load background GetComponent <SpriteRenderer>().sprite = cd.background; _isEvent = cd.isEvent; //Load enemies foreach (GameObject e in cd.enemies) { //Instantiate enemy GameObject enemy = Instantiate(e); EnemyController controller = enemy.GetComponent <EnemyController>(); PlayerStats stats = enemy.GetComponent <PlayerStats>(); stats.ReloadEnchantments(); stats.LoadPassiveEffects(); int index = Enemies.Count; //Add enemy to combat manager Enemies.Add(enemy); //Set enemy position float x = _enemyX * camera.pixelWidth; float y = GetSpot(Enemies) * camera.pixelHeight; Vector3 pos = new Vector3(x, y, 0); enemy.transform.position = camera.ScreenToWorldPoint(pos); enemy.transform.position = new Vector3(enemy.transform.position.x, enemy.transform.position.y, 0); enemy.SetActive(true); stats.CombatPosition = index; //Set up healthbars and stuff GameObject combatUI = Instantiate((Resources.Load("CombatUI") as GameObject)); combatUI.GetComponent <CombatUI>().Set(stats, false, controller.Name); controller.CombatUI = combatUI; controller.BuffIcon = Instantiate((Resources.Load("BuffIcon") as GameObject)).GetComponent <BuffIcon>(); enemy.GetComponent <PlayerStats>().Cooldown = 0; } }
/// <summary> /// Verify a specific pair of entities involved in a message. /// </summary> /// <param name="message"></param> /// <param name="target"></param> /// <param name="death"></param> internal static void VerifyEntities(ref Message message, TargetDetails target, bool death) { if (message == null) { throw new ArgumentNullException("message"); } if (message.EventDetails == null) { throw new ArgumentNullException("message.EventDetails"); } if (message.EventDetails.CombatDetails == null) { throw new ArgumentNullException("message.EventDetails.CombatDetails"); } if (target == null) { throw new ArgumentNullException("target"); } uint msgCode = message.MessageCode; CombatDetails combatDetails = message.EventDetails.CombatDetails; EntityType supposedActorType = ParseCodes.Instance.GetActorEntityType(message.MessageCode); EntityType supposedTargetType = ParseCodes.Instance.GetTargetEntityType(message.MessageCode); // Disambiguate Unknowns based on known message code values. if (combatDetails.ActorEntityType == EntityType.Unknown) { combatDetails.ActorEntityType = supposedActorType; } if (target.EntityType == EntityType.Unknown) { target.EntityType = supposedTargetType; } // If the message is of type Aid, both entities should be of the same type. if (combatDetails.InteractionType == InteractionType.Aid) { // If one or the other (but not both) are type mob, one of them // must be charmed. Since I don't believe it's possible for a mob // to aid a charmed player, and a charmed player cannot do any actions // except melee, if one of these is a mob, it must be charmed. if ((combatDetails.ActorEntityType == EntityType.Mob) ^ (target.EntityType == EntityType.Mob)) { // However exclude instances of a skillchain as an actor in // cases of skillchains healing mobs (eg: elementals, puks, etc). if (combatDetails.ActorEntityType != EntityType.Skillchain) { if (combatDetails.ActorEntityType == EntityType.Mob) { combatDetails.ActorEntityType = EntityType.CharmedMob; } else if (target.EntityType == EntityType.Mob) { target.EntityType = EntityType.CharmedMob; } } } if (combatDetails.ActorEntityType == EntityType.Unknown) { if (target.EntityType == EntityType.Player) { combatDetails.ActorEntityType = EntityType.Player; } else if (target.EntityType == EntityType.Unknown) { if ((combatDetails.ActorPlayerType == ActorPlayerType.Self) || (combatDetails.ActorPlayerType == ActorPlayerType.Party) || (combatDetails.ActorPlayerType == ActorPlayerType.Alliance)) { combatDetails.ActorEntityType = EntityType.Player; target.EntityType = EntityType.Player; } } } else if (target.EntityType == EntityType.Unknown) { if (combatDetails.ActorEntityType != EntityType.Mob) { target.EntityType = EntityType.Player; } } return; } // If the message is of type Harm, the entities should be of different types. // Also handle unknown interaction types here. if (combatDetails.InteractionType == InteractionType.Harm) { // If both entities are mobs, one of them must be charmed. if ((combatDetails.ActorEntityType == EntityType.Mob) && (target.EntityType == EntityType.Mob)) { // If they have different names, see if we have one registered // as the most recently charmed mob. if (combatDetails.ActorName != target.Name) { if (combatDetails.ActorName == EntityManager.Instance.LastCharmedMob) { combatDetails.ActorEntityType = EntityType.CharmedMob; return; } if (target.Name == EntityManager.Instance.LastCharmedMob) { target.EntityType = EntityType.CharmedMob; return; } // If neither are registered as the most recent, see if either // (but not both) have been registered as charmed. EntityType actorCharmEntity = EntityManager.Instance.LookupCharmedEntity(combatDetails.ActorName); EntityType targetCharmEntity = EntityManager.Instance.LookupCharmedEntity(target.Name); if ((actorCharmEntity == EntityType.CharmedMob) ^ (targetCharmEntity == EntityType.CharmedMob)) { if (actorCharmEntity == EntityType.CharmedMob) { combatDetails.ActorEntityType = EntityType.CharmedMob; return; } if (targetCharmEntity == EntityType.CharmedMob) { target.EntityType = EntityType.CharmedMob; return; } } } // At this point, either the mobs have the same name, or both mobs are // listed in our entity list as possibly charmed and neither one is our // 'last charmed' mob. Cannot accurately determine which is which, so random. if (death == true) { // If it's a death, defer resolution until we know if we // get experience. combatDetails.FlagPetDeath = true; } else { // Otherwise just random it. if (random.Next(1000) < 500) { target.EntityType = EntityType.CharmedMob; } else { combatDetails.ActorEntityType = EntityType.CharmedMob; } } } // If both entities are players, one of them must be charmed, // or one of them is an NM. // Charmed players will not attack NPCs/Pets/etc. if ((combatDetails.ActorEntityType == EntityType.Player) && (target.EntityType == EntityType.Player)) { // Charmed players can only melee. If this is anything aside from // melee, one of the entities must be an NM if (combatDetails.ActionType != ActionType.Melee) { // This is probably an NM. Set the entity type based on the message code. if (ParseCodes.Instance.GetActorEntityType(msgCode) == EntityType.Mob) { combatDetails.ActorEntityType = EntityType.Mob; return; } else if (ParseCodes.Instance.GetTargetEntityType(msgCode) == EntityType.Mob) { target.EntityType = EntityType.Mob; return; } // This could be the result of a busted Corsair roll. If so, leave as is. if ((string.IsNullOrEmpty(target.EffectName) == false) && (JobAbilities.CorRolls.Contains(target.EffectName) == true)) { return; } // Check if either combatant is in the entity table already. // If not, then a player is likely initiating action against an NM. var actorEntityList = EntityManager.Instance.LookupEntity(combatDetails.ActorName); var targetEntityList = EntityManager.Instance.LookupEntity(target.Name); if (targetEntityList.Count == 0) { target.EntityType = EntityType.Mob; return; } // If we have not yet determined the entity type, it's probably an NM. if (targetEntityList.Contains(EntityType.Unknown)) { target.EntityType = EntityType.Mob; return; } // If the target is already known (ie: they're present in the requested // entity list above) and the actor is unknown, then presumably the // NM is taking action against the player. if (actorEntityList.Count == 0) { combatDetails.ActorEntityType = EntityType.Mob; return; } // If we have not yet determined the entity type, it's probably an NM. if (actorEntityList.Contains(EntityType.Unknown)) { combatDetails.ActorEntityType = EntityType.Mob; return; } // Otherwise it's likely spells/etc cast on charmed players target.EntityType = EntityType.CharmedPlayer; return; } // If we get here, this is either melee, or we're not sure of the // defined entity types. Try looking up details from the entity manager first. EntityType actorCharmEntity = EntityManager.Instance.LookupCharmedEntity(combatDetails.ActorName); if (actorCharmEntity == EntityType.CharmedPlayer) { combatDetails.ActorEntityType = EntityType.CharmedPlayer; return; } EntityType targetCharmEntity = EntityManager.Instance.LookupCharmedEntity(target.Name); if (targetCharmEntity == EntityType.CharmedPlayer) { target.EntityType = EntityType.CharmedPlayer; return; } // If we don't get anything from the entity manager, assume the // aggressive melee'er is the charmed one. combatDetails.ActorEntityType = EntityType.CharmedPlayer; return; } // If a pet is attacking a player, it's more likely that // the pet is actually a mob (eg: Odin the avatar vs // Odin the NM). Confirm with the supposedActorType // for the message code. if ((combatDetails.ActorEntityType == EntityType.Pet) && (target.EntityType == EntityType.Player) && (supposedActorType == EntityType.Mob)) { combatDetails.ActorEntityType = EntityType.Mob; return; } // Otherwise, if a pet is attacking a player, that player // must be charmed. if ((combatDetails.ActorEntityType == EntityType.Pet) && (target.EntityType == EntityType.Player)) { target.EntityType = EntityType.CharmedPlayer; return; } // If target is a mob and actor hasn't been identified yet, actor // must be a player. if ((combatDetails.ActorEntityType == EntityType.Unknown) && (target.EntityType == EntityType.Mob)) { combatDetails.ActorEntityType = EntityType.Player; return; } // If actor is a mob and target hasn't been identified yet, target // must be a player. if ((combatDetails.ActorEntityType == EntityType.Mob) && (target.EntityType == EntityType.Unknown)) { target.EntityType = EntityType.Player; return; } // If actor is a player and target hasn't been identified yet, target // must be a mob. (higher priority assumption than that actor is charmed // by the point we need to make this distinction) if ((combatDetails.ActorEntityType == EntityType.Player) && (target.EntityType == EntityType.Unknown)) { target.EntityType = EntityType.Mob; return; } } if (combatDetails.InteractionType == InteractionType.Death) { // If a mob killed a pet, we'd know the entity type of the target. // As such, if there's an unknown target entity type, it must be a player. if ((combatDetails.ActorEntityType == EntityType.Mob) && (target.EntityType == EntityType.Unknown)) { target.EntityType = EntityType.Player; } // If target killed is a mob, we know the actor must be a player if // they are currently unknown (can't charm player-named mobs). else if ((combatDetails.ActorEntityType == EntityType.Unknown) && (target.EntityType == EntityType.Mob)) { combatDetails.ActorEntityType = EntityType.Player; } } }
//give rewards to player after combat as directed by the combat portal's specifications public void GiveRewards() { CombatDetails details = CombatDetails.GetComponent <CombatDetails>(); foreach (GameObject player in Players) { if (!player) { continue; } if (!player.GetComponent <PlayerController>().CPU)//dont give rewards to cpu players { List <int> attemptedRewards = new List <int>(); int rewardsGiven = 0; List <GameObject> rewards = new List <GameObject>(); List <float> rates = details.rewardRates; List <GameObject> item = details.rewards; List <bool> guaranteedDrops = details.guaranteedDrop; //Add guaranteed drop items as well for (int i = 0; i < guaranteedDrops.Count; i++) { if (guaranteedDrops[i] == true) { rewards.Add(item[i]); rewardsGiven++; attemptedRewards.Add(i); } } //loop through rates giving cooresponding reward if rng says so, beaks if maxrewards given is met for (int i = 0; i < rates.Count; i++) { if (attemptedRewards.Count >= rates.Count) { break; } if (rewardsGiven >= details.maxRewards) { break; } float reward = Random.Range(0f, 1f); //randomly select an item int index; while (attemptedRewards.Contains(index = Random.Range(0, rates.Count))) { if (attemptedRewards.Contains(index)) { continue; } } //if ((reward < rates[index] || (details.minRewards != 0 && details.minRewards - rewardsGiven == rates.Count - i)) && guaranteedDrops[index] == false) if (reward < rates[index] || (details.minRewards != 0 && details.minRewards - rewardsGiven == rates.Count - i)) { //Debug.Log("Adding " + item[index] + " to inventory as battle reward"); rewards.Add(item[index]); rewardsGiven++; } attemptedRewards.Add(index); } //Add rewards to inventory foreach (GameObject reward in rewards) { player.GetComponent <Inventory>().AddItemToInventory(reward.GetComponent <Item>()); player.GetComponent <EventManager>().Event(new List <object>() { GameAction.LOOTED, reward.GetComponent <Item>().ID, 1 }); } _networkManager.DBGetCombatRewards(rewardsGiven); //give xp and gold int xp = Random.Range(details.minXp, CombatDetails.GetComponent <CombatDetails>().maxXp); int gold = Random.Range(details.minGold, CombatDetails.GetComponent <CombatDetails>().maxGold); player.GetComponent <Inventory>().AddGold(gold); bool levelup = player.GetComponent <PlayerController>().AddXP(xp); //display what was given StartCoroutine(PrintRewards(rewards, xp, gold, levelup)); } } }