/// <summary> /// Occurs when you switch between weapons (primary -> secondary) /// </summary> private void CM_WEAPONSWITCH(CMSG_WEAPONSWITCH cpkt) { //Helper variables byte prev_weapontype = 0; byte next_weapontype = 0; //Deapplies the currrent stats lock (this.character._status) { int WeaponIndex = (this.character.weapons.ActiveWeaponIndex == 1) ? this.character.weapons.SeconairyWeaponIndex : this.character.weapons.PrimaryWeaponIndex; if (WeaponIndex < this.character.weapons.UnlockedWeaponSlots) { Weapon CurrentWeapon = this.character.weapons[WeaponIndex]; prev_weapontype = CurrentWeapon._weapontype; if (CurrentWeapon != null && CurrentWeapon._active == 1) { //Deapplies the weapon stats this.character._status.MaxWMAttack -= (ushort)CurrentWeapon.Info.max_magic_attack; this.character._status.MinWMAttack -= (ushort)CurrentWeapon.Info.min_magic_attack; this.character._status.MaxWPAttack -= (ushort)CurrentWeapon.Info.max_short_attack; this.character._status.MinWPAttack -= (ushort)CurrentWeapon.Info.min_short_attack; this.character._status.MaxWRAttack -= (ushort)CurrentWeapon.Info.max_range_attack; this.character._status.MinWRAttack -= (ushort)CurrentWeapon.Info.min_range_attack; this.character._status.Updates |= 2; //Deapplies the fusion stone if (CurrentWeapon._fusion > 0) Common.Skills.DeleteStaticAddition(this.character, CurrentWeapon._fusion); //Deapplies alterstone additions for (int i = 0; i < 8; i++) { uint addition = CurrentWeapon.Slots[i]; if (addition > 0) { Singleton.Additions.DeapplyAddition(addition, character); } } } } } //Toggles the weapons index this.character.weapons.ActiveWeaponIndex ^= 1; int ShieldIndex = (this.character.weapons.ActiveWeaponIndex == 1) ? 15 : 14; Rag2Item shield = this.character.Equipment[ShieldIndex]; lock (this.character._status) { int NewWeaponIndex = (this.character.weapons.ActiveWeaponIndex == 1) ? this.character.weapons.SeconairyWeaponIndex : this.character.weapons.PrimaryWeaponIndex; if (NewWeaponIndex < this.character.weapons.UnlockedWeaponSlots) { //Apples the battle stats Weapon CurrentWeapon = this.character.weapons[NewWeaponIndex]; next_weapontype = CurrentWeapon._weapontype; if (CurrentWeapon != null && CurrentWeapon._active == 1) { this.character._status.MaxWMAttack += (ushort)CurrentWeapon.Info.max_magic_attack; this.character._status.MinWMAttack += (ushort)CurrentWeapon.Info.min_magic_attack; this.character._status.MaxWPAttack += (ushort)CurrentWeapon.Info.max_short_attack; this.character._status.MinWPAttack += (ushort)CurrentWeapon.Info.min_short_attack; this.character._status.MaxWRAttack += (ushort)CurrentWeapon.Info.max_range_attack; this.character._status.MinWRAttack += (ushort)CurrentWeapon.Info.min_range_attack; this.character._status.Updates |= 2; } //Reapplies the fusion stone if (CurrentWeapon._fusion > 0) Common.Skills.CreateAddition(this.character, CurrentWeapon._fusion); //Reapplies alterstone additions for (int i = 0; i < 8; i++) { uint addition = CurrentWeapon.Slots[i]; if (addition > 0) { Singleton.Additions.DeapplyAddition(addition, character); } } } if (prev_weapontype != next_weapontype) { foreach (Skill skill in this.character.learnedskills) { //If it's a pasive skill if (skill.info.skilltype == 2) { bool PreviousAble = skill.info.requiredWeapons[prev_weapontype] == 1; bool NextAble = skill.info.requiredWeapons[next_weapontype] == 1; if (PreviousAble == false && NextAble == true) { Singleton.Additions.ApplyAddition(skill.info.addition, this.character); this.character._status.Updates |= 2; } else if (NextAble == false && PreviousAble == true) { Singleton.Additions.DeapplyAddition(skill.info.addition, this.character); this.character._status.Updates |= 2; } } } } } //Switch the weapons Point oldPos = this.character.Position; Regiontree tree = this.character.currentzone.Regiontree; foreach (Character regionObject in tree.SearchActors(this.character, SearchFlags.Characters)) { if (regionObject.id == this.character.id) { SMSG_WEAPONSWITCH spkt = new SMSG_WEAPONSWITCH(); spkt.slotid = cpkt.slotid; spkt.SessionId = this.character.id; this.Send((byte[])spkt); } else if (Point.IsInSightRangeByRadius(regionObject.Position, oldPos)) { SMSG_SHOWWEAPON spkt = new SMSG_SHOWWEAPON(); spkt.ActorID = this.character.id; spkt.AugeID = this.character.ComputeAugeSkill(); spkt.SessionId = regionObject.id; regionObject.client.Send((byte[])spkt); SMSG_CHANGEEQUIPMENT spkt2 = new SMSG_CHANGEEQUIPMENT(); spkt2.ActorID = this.character.id; spkt2.Slot = (byte)ShieldIndex; spkt2.ItemID = (shield != null) ? shield.info.item : 0; spkt2.Dye = shield.dyecolor; spkt2.SessionId = regionObject.id; regionObject.client.Send((byte[])spkt2); } } //Does the switch Tasks.LifeCycle.Update(this.character); }
/// <summary> /// This occurs after adding a auge skill to the weaponary /// </summary> /// <param name="cpkt"></param> private void CM_WEAPONAUGE(CMSG_WEAPONAUGE cpkt) { Rag2Item item = this.character.container[cpkt.Index]; Weapon wep = this.character.weapons[cpkt.WeaponSlot]; if (item == null) return; wep._augeskill = item.info.skill; Point oldPos = this.character.Position; Regiontree tree = this.character.currentzone.Regiontree; bool IsActiveItem = cpkt.WeaponSlot == (byte)((character.weapons.ActiveWeaponIndex == 0) ? character.weapons.PrimaryWeaponIndex : character.weapons.SeconairyWeaponIndex); //Update item count int newLength = item.count - 1; if (newLength > 0) { item.count = newLength; SMSG_UPDATEITEM spkt2 = new SMSG_UPDATEITEM(); spkt2.Amount = (byte)newLength; spkt2.UpdateReason = 0; spkt2.UpdateType = 4; spkt2.Container = 2; spkt2.SessionId = this.character.id; spkt2.Index = cpkt.Index; this.Send((byte[])spkt2); } else { this.character.container.RemoveAt(cpkt.Index); SMSG_DELETEITEM spkt3 = new SMSG_DELETEITEM(); spkt3.UpdateReason = 0; spkt3.Container = 2; spkt3.Index = cpkt.Index; spkt3.SessionId = this.character.id; this.Send((byte[])spkt3); } //Update all objects foreach (Character regionObject in tree.SearchActors(SearchFlags.Characters)) { if (regionObject.id == this.character.id) { SMSG_ENCHANTMENT spkt = new SMSG_ENCHANTMENT(); spkt.Unknown1 = 1; spkt.Unknown2 = cpkt.WeaponSlot; spkt.Weaponslot = cpkt.Slot; spkt.SkillId = wep._augeskill; spkt.SessionId = this.character.id; this.Send((byte[])spkt); } else if (IsActiveItem && Point.IsInSightRangeByRadius(regionObject.Position, oldPos)) { SMSG_SHOWWEAPON spkt = new SMSG_SHOWWEAPON(); spkt.ActorID = this.character.id; spkt.AugeID = this.character.ComputeAugeSkill(); spkt.SessionId = regionObject.id; regionObject.client.Send((byte[])spkt); } } }
/// <summary> /// Occurs when changing the weapon /// </summary> private void CM_WEAPONMOVE(CMSG_WEAPONMOVE cpkt) { bool isselectedweapon = cpkt.Slot == this.character.weapons.ActiveWeaponIndex; byte prev_slot = (cpkt.Slot == 1) ? this.character.weapons.SeconairyWeaponIndex : this.character.weapons.PrimaryWeaponIndex; byte next_slot = cpkt.Slot; byte prev_weapontype = 0; byte next_weapontype = 0; if (isselectedweapon) { lock (this.character._status) { if (prev_slot < this.character.weapons.UnlockedWeaponSlots) { Weapon CurrentWeapon = this.character.weapons[prev_slot]; prev_weapontype = CurrentWeapon._weapontype; if (CurrentWeapon != null && CurrentWeapon._active == 1) { //Deapplies the weapon stats this.character._status.MaxWMAttack -= (ushort)CurrentWeapon.Info.max_magic_attack; this.character._status.MinWMAttack -= (ushort)CurrentWeapon.Info.min_magic_attack; this.character._status.MaxWPAttack -= (ushort)CurrentWeapon.Info.max_short_attack; this.character._status.MinWPAttack -= (ushort)CurrentWeapon.Info.min_short_attack; this.character._status.MaxWRAttack -= (ushort)CurrentWeapon.Info.max_range_attack; this.character._status.MinWRAttack -= (ushort)CurrentWeapon.Info.min_range_attack; this.character._status.Updates |= 2; //Deapplies the fusion stone if (CurrentWeapon._fusion > 0) Common.Skills.DeleteStaticAddition(this.character, CurrentWeapon._fusion); //Deapplies alterstone additions for (int i = 0; i < 8; i++) { uint addition = CurrentWeapon.Slots[i]; if (addition > 0) { Singleton.Additions.DeapplyAddition(addition, character); } } } } if (next_slot < this.character.weapons.UnlockedWeaponSlots) { //Apples the battle stats Weapon CurrentWeapon = this.character.weapons[next_slot]; next_weapontype = CurrentWeapon._weapontype; if (CurrentWeapon != null && CurrentWeapon._active == 1) { this.character._status.MaxWMAttack += (ushort)CurrentWeapon.Info.max_magic_attack; this.character._status.MinWMAttack += (ushort)CurrentWeapon.Info.min_magic_attack; this.character._status.MaxWPAttack += (ushort)CurrentWeapon.Info.max_short_attack; this.character._status.MinWPAttack += (ushort)CurrentWeapon.Info.min_short_attack; this.character._status.MaxWRAttack += (ushort)CurrentWeapon.Info.max_range_attack; this.character._status.MinWRAttack += (ushort)CurrentWeapon.Info.min_range_attack; this.character._status.Updates |= 2; } //Reapplies the fusion stone if (CurrentWeapon._fusion > 0) Common.Skills.CreateAddition(this.character, CurrentWeapon._fusion); //Reapplies alterstone additions for (int i = 0; i < 8; i++) { uint addition = CurrentWeapon.Slots[i]; if (addition > 0) { Singleton.Additions.DeapplyAddition(addition, character); } } } if (prev_weapontype != next_weapontype) { foreach (Skill skill in this.character.learnedskills) { //If it's a pasive skill if (skill.info.skilltype == 2) { bool PreviousAble = skill.info.requiredWeapons[prev_weapontype] == 1; bool NextAble = skill.info.requiredWeapons[next_weapontype] == 1; if (PreviousAble == false && NextAble == true) Singleton.Additions.ApplyAddition(skill.info.addition, this.character); else if (NextAble == false && PreviousAble == true) Singleton.Additions.DeapplyAddition(skill.info.addition, this.character); } } } } } //Switch the weapons Point oldPos = this.character.Position; Regiontree tree = this.character.currentzone.Regiontree; foreach (Character regionObject in tree.SearchActors(SearchFlags.Characters)) { if (regionObject.id == this.character.id) { SMSG_WEAPONMOVE spkt = new SMSG_WEAPONMOVE(); spkt.Unknown1 = cpkt.Index; spkt.Unknown2 = cpkt.WeaponSlot; spkt.Weaponslot = cpkt.Slot; spkt.SessionId = this.character.id; regionObject.client.Send((byte[])spkt); } else if (isselectedweapon && Point.IsInSightRangeByRadius(regionObject.Position, oldPos)) { SMSG_SHOWWEAPON spkt = new SMSG_SHOWWEAPON(); spkt.ActorID = this.character.id; spkt.AugeID = this.character.ComputeAugeSkill(); spkt.SessionId = regionObject.id; regionObject.client.Send((byte[])spkt); } } Tasks.LifeCycle.Update(this.character); }
/// <summary> /// Requests to change the job. /// </summary> /// <param name="cpkt"></param> private void CM_CHARACTER_JOBCHANGE(CMSG_CHANGEJOB cpkt) { JobChangeCollection collection = this.character.Tag as JobChangeCollection; if (collection == null || !collection.IsJobAvailable(cpkt.Job)) { //Job change failed SMSG_JOBCHANGED spkt = new SMSG_JOBCHANGED(); spkt.Job = this.character.job; spkt.Result = 1; spkt.SessionId = this.character.id; spkt.SourceActor = this.character.id; this.Send((byte[])spkt); return; } else if (collection.GetJobTrasferFee(cpkt.Job) > this.character.ZENY) { //Not enough money Common.Errors.GeneralErrorMessage(this.character, (uint)Generalerror.NotEnoughMoney); SMSG_JOBCHANGED spkt = new SMSG_JOBCHANGED(); spkt.Job = this.character.job; spkt.Result = 1; spkt.SessionId = this.character.id; spkt.SourceActor = this.character.id; this.Send((byte[])spkt); return; } else { this.character.ZENY -= collection.GetJobTrasferFee(cpkt.Job); CommonFunctions.UpdateZeny(this.character); } //Helper variables List<int> EnabledEquipment = new List<int>(); List<int> DisabledEquipment = new List<int>(); bool ChangeWeapon = cpkt.ChangeWeapon == 1; bool IsActiveWeapon = this.character.weapons.IsActiveSlot(cpkt.WeaponSlot); Weapon selectedWeapon = this.character.weapons[cpkt.WeaponSlot]; #region Update Character Information lock (this.character) { //Change the job and joblevel int hpbefore = Singleton.CharacterConfiguration.CalculateMaximumHP(this.character); int spbefore = Singleton.CharacterConfiguration.CalculateMaximumSP(this.character); this.character.CharacterJobLevel[this.character.job] = this.character.jlvl; this.character.jlvl = this.character.CharacterJobLevel[cpkt.Job]; this.character.job = cpkt.Job; this.character.Jexp = Singleton.experience.FindRequiredJexp(this.character.jlvl); int hpafter = Singleton.CharacterConfiguration.CalculateMaximumHP(this.character); int spafter = Singleton.CharacterConfiguration.CalculateMaximumSP(this.character); this.character._status.CurrentHp += (ushort)(hpbefore - hpafter); this.character._status.CurrentSp += (ushort)(spbefore - spafter); this.character._status.Updates |= 1; } #endregion Update Character Information #region Refresh Weapon //Deapply current weapon info if (ChangeWeapon && IsActiveWeapon && selectedWeapon != null) { BattleStatus status = this.character._status; status.MaxWMAttack -= (ushort)selectedWeapon.Info.max_magic_attack; status.MinWMAttack -= (ushort)selectedWeapon.Info.min_magic_attack; status.MaxWPAttack -= (ushort)selectedWeapon.Info.max_short_attack; status.MinWPAttack -= (ushort)selectedWeapon.Info.min_short_attack; status.MaxWRAttack -= (ushort)selectedWeapon.Info.max_range_attack; status.MinWRAttack -= (ushort)selectedWeapon.Info.min_range_attack; status.Updates |= 2; //Reapplies alterstone additions for (int i = 0; i < 8; i++) { uint addition = selectedWeapon.Slots[i]; if (addition > 0) { Singleton.Additions.DeapplyAddition(addition, character); } } } #endregion Refresh Weapon #region Refresh Weapon if (ChangeWeapon && selectedWeapon != null) { Singleton.Weapons.ChangeWeapon(cpkt.Job, cpkt.PostFix, selectedWeapon); SMSG_WEAPONCHANGE spkt = new SMSG_WEAPONCHANGE(); spkt.Auge = selectedWeapon._augeskill; spkt.SessionId = this.character.id; spkt.Suffix = cpkt.PostFix; spkt.Index = cpkt.WeaponSlot; spkt.WeaponType = (byte)selectedWeapon._type; this.Send((byte[])spkt); } #endregion Refresh Weapon #region Refresh Skills { //Remove all skills foreach (Skill skill in this.character.learnedskills) { //Remove the skill SMSG_SKILLREMOVE spkt = new SMSG_SKILLREMOVE(); spkt.Unknown = skill.info.skilltype; spkt.SessionId = this.character.id; spkt.SkillId = skill.info.skillid; this.Send((byte[])spkt); //Save only experience if it's maxed-out. Singleton.Database.UpdateSkill(this.character, skill.Id, (skill.Experience == skill.info.maximumexperience) ? skill.info.maximumexperience : 0); //Deapply passive skills bool canUse = Singleton.SpellManager.CanUse(this.character, skill.info); if (skill.info.skilltype == 2 && canUse) Singleton.Additions.DeapplyAddition(skill.info.addition, character); } //Remove all learned skills in an instant this.character.learnedskills.Clear(); Singleton.Database.LoadSkills(this.character); //Retrieve job speciafic skills foreach (Skill skill in this.character.learnedskills) { //Add the skill SMSG_SKILLADD spkt = new SMSG_SKILLADD(); spkt.SessionId = this.character.id; spkt.SkillId = skill.info.skillid; spkt.Slot = 0; this.Send((byte[])spkt); //Deapply passive skills bool canUse = Singleton.SpellManager.CanUse(this.character, skill.info); if (skill.info.skilltype == 2 && canUse) Singleton.Additions.ApplyAddition(skill.info.addition, character); } } #endregion Refresh Skills #region Refresh Weapon //Apply current weapon info if (ChangeWeapon && IsActiveWeapon && selectedWeapon != null) { //Apply status BattleStatus status = this.character._status; status.MaxWMAttack += (ushort)selectedWeapon.Info.max_magic_attack; status.MinWMAttack += (ushort)selectedWeapon.Info.min_magic_attack; status.MaxWPAttack += (ushort)selectedWeapon.Info.max_short_attack; status.MinWPAttack += (ushort)selectedWeapon.Info.min_short_attack; status.MaxWRAttack += (ushort)selectedWeapon.Info.max_range_attack; status.MinWRAttack += (ushort)selectedWeapon.Info.min_range_attack; status.Updates |= 2; //Reapplies alterstone additions for (int i = 0; i < 8; i++) { uint addition = selectedWeapon.Slots[i]; if (addition > 0) { Singleton.Additions.ApplyAddition(addition, character); } } } #endregion Refresh Weapon #region Refresh Equipment { //Disable equipment for (int i = 0; i < 16; i++) { //Verify if item exists Rag2Item item = this.character.Equipment[i]; if (item == null || item.info == null) continue; //Verify if the item changed states bool Active = item.active == 1; bool NewActive = this.character.jlvl >= item.info.JobRequirement[cpkt.Job - 1]; if (Active == NewActive) continue; item.active = (byte)((NewActive == true) ? 1 : 0); //Adjust the item SMSG_ITEMADJUST spkt = new SMSG_ITEMADJUST(); spkt.Container = 1; spkt.Function = 5; spkt.Slot = (byte)i; spkt.SessionId = this.character.id; spkt.Value = item.active; this.Send((byte[])spkt); //Deapply additions if (NewActive) { EnabledEquipment.Add(i); Singleton.Additions.ApplyAddition(item.info.option_id, character); } else { DisabledEquipment.Add(i); Singleton.Additions.DeapplyAddition(item.info.option_id, character); } } //Update other stats //Common.Internal.CheckWeaponary(this.character); //CommonFunctions.UpdateCharacterInfo(this.character, 0); //CommonFunctions.SendBattleStatus(this.character); } #endregion Refresh Equipment #region Refresh Appereance { Regiontree tree = this.character.currentzone.Regiontree; foreach (Character regionObject in tree.SearchActors(SearchFlags.Characters)) { SMSG_JOBCHANGED spkt = new SMSG_JOBCHANGED(); spkt.SessionId = regionObject.id; spkt.SourceActor = this.character.id; spkt.Job = cpkt.Job; regionObject.client.Send((byte[])spkt); if (regionObject.id != this.character.id) { if (IsActiveWeapon) { uint auge = (character.FindRequiredRootSkill(selectedWeapon.Info.weapon_skill)) ? selectedWeapon._augeskill : 0; SMSG_SHOWWEAPON spkt2 = new SMSG_SHOWWEAPON(); spkt2.ActorID = this.character.id; spkt2.AugeID = auge; spkt2.SessionId = regionObject.id; regionObject.client.Send((byte[])spkt2); } foreach (byte i in EnabledEquipment) { Rag2Item item = this.character.Equipment[i]; SMSG_CHANGEEQUIPMENT spkt2 = new SMSG_CHANGEEQUIPMENT(); spkt2.SessionId = regionObject.id; spkt2.ActorID = this.character.id; spkt2.Slot = i; spkt2.ItemID = item.info.item; spkt2.Dye = item.dyecolor; regionObject.client.Send((byte[])spkt2); } foreach (byte i in DisabledEquipment) { SMSG_CHANGEEQUIPMENT spkt2 = new SMSG_CHANGEEQUIPMENT(); spkt2.SessionId = regionObject.id; spkt2.ActorID = this.character.id; spkt2.Slot = i; spkt2.ItemID = 0; spkt2.Dye = 0; regionObject.client.Send((byte[])spkt2); } } } } #endregion Refresh Appereance #region Refresh Party { //Process party members SMSG_PARTYMEMBERJOB spkt = new SMSG_PARTYMEMBERJOB(); spkt.Job = cpkt.Job; spkt.SessionId = this.character.id; spkt.ActorId = this.character.id; spkt.Index = 1; SMSG_PARTYMEMBERJLVL spkt2 = new SMSG_PARTYMEMBERJLVL(); spkt2.Jvl = this.character.jlvl; spkt2.ActorId = this.character.id; spkt2.Index = 1; if (this.character.sessionParty != null) { foreach (Character target in this.character.sessionParty.GetCharacters()) { //Send over Job change spkt.SessionId = target.id; target.client.Send((byte[])spkt); //Send over jlvl change spkt2.SessionId = target.id; target.client.Send((byte[])spkt2); } } } #endregion Refresh Party #region Refresh LifeCycle Tasks.LifeCycle.Update(this.character); #endregion Refresh LifeCycle }