private void CreateMagic(GameUser userEntity) { UserMagic userMagic = new UserMagic { UserID = userEntity.UserID, IsEnabled = true, MagicID = new GameUser().UserMagicID, MagicLv = 1, MagicType = MagicType.MoFaZhen }; var cacheUserMagic = new GameDataCacheSet <UserMagic>(); cacheUserMagic.Add(userMagic); cacheUserMagic.Update(); //初始阵法 string[] gridRange = new ConfigCacheSet <MagicLvInfo>().FindKey(userMagic.MagicID, userMagic.MagicLv).GridRange.Split(new char[] { ',' }); if (gridRange.Length > 0) { string grid = gridRange[0]; UserEmbattle userEmbattle = new UserEmbattle { UserID = userEntity.UserID, GeneralID = generalID, MagicID = userMagic.MagicID, Position = grid.ToShort() }; var cacheEmbattle = new GameDataCacheSet <UserEmbattle>(); cacheEmbattle.Add(userEmbattle); cacheEmbattle.Update(); } }
protected override void ProcessCmd(string[] args) { int magicID = args.Length > 0 ? args[0].Trim().ToInt() : 0; short magicLv = args.Length > 1 ? args[1].Trim().ToShort() : (short)1; var cacheSet = new GameDataCacheSet <UserMagic>(); var userMagic = cacheSet.FindKey(UserID, magicID); MagicInfo magic = new ConfigCacheSet <MagicInfo>().FindKey(magicID); if (magic == null) { return; } if (userMagic == null) { userMagic = new UserMagic() { UserID = UserID, MagicID = magicID, MagicLv = magicLv, IsEnabled = false, MagicType = magic.MagicType, }; cacheSet.Add(userMagic, GameEnvironment.CacheUserPeriod); } else { userMagic.MagicLv = magicLv; } }
protected override void ProcessTarget() { if (Target == null || !CanAttack) { return; } Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation); if (InAttackRange()) { if (Envir.Time > AttackTime) { if (Master != null) { if (Master.Race == ObjectType.Player) { PlayerObject ob = (PlayerObject)Master; UserMagic tmp = ob.GetMagic(Spell.SummonSkeleton); if (tmp != null && tmp.Level >= 3) { CHMAttack(); } else { Attack(); } } if (Target.Dead) { FindTarget(); } return; } else { Attack(); } if (Target.Dead) { FindTarget(); } return; } } if (Envir.Time < ShockTime) { Target = null; return; } if (Info.TeleportBack && Envir.Random.Next(7) == 0 && Target.CurrentMap == CurrentMap) { Teleport(Target.CurrentMap, Target.Back); } else { MoveTo(Target.CurrentLocation); } }
protected override void ProcessCmd(string[] args) { int magicID = args.Length > 0 ? args[0].Trim().ToInt() : 0; short magicLv = args.Length > 1 ? args[1].Trim().ToShort() : (short)1; var cacheSet = new PersonalCacheStruct <UserMagic>(); var userMagic = cacheSet.FindKey(UserID, magicID); MagicInfo magic = new ShareCacheStruct <MagicInfo>().FindKey(magicID); if (magic == null) { return; } if (userMagic == null) { userMagic = new UserMagic() { UserID = UserID, MagicID = magicID, MagicLv = magicLv, IsEnabled = false, MagicType = magic.MagicType, }; cacheSet.Add(userMagic); } else { userMagic.MagicLv = magicLv; } }
public override void CleanUp() { base.CleanUp(); Owner = null; Magic = null; Targets?.Clear(); }
protected bool CanUseMagic(UserMagic magic) { if (magic == null) { return(false); } if (MagicCost(magic) > MP) { return(false); } if (magic.Key <= 0) { return(false); } return(true); }
protected override void ProcessAttack() { if (Target == null || Target.Dead) { return; } TargetDistance = Functions.MaxDistance(CurrentLocation, Target.CurrentLocation); Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation); UserMagic magic = GetMagic(Spell.HeavenlySword); HasHeavenlySword = CanCast && CanUseMagic(magic); if (HasHeavenlySword && TargetDistance == 2) { BeginMagic(magic.Spell, Direction, Target.ObjectID, Target.CurrentLocation); return; } }
private void MagicKey(C.MagicKey p) { if (Stage != GameStage.Game) { return; } for (int i = 0; i < Player.Info.Magics.Count; i++) { UserMagic magic = Player.Info.Magics[i]; if (magic.Spell != p.Spell) { if (magic.Key == p.Key) { magic.Key = 0; } continue; } magic.Key = p.Key; } }
/// <summary> /// 初始化魔法阵 /// </summary> /// <param name="userId"></param> /// <param name="userLv"></param> private static void InitMagicEmbattle(string userId, short userLv) { List <UserMagic> userMagicList = new GameDataCacheSet <UserMagic>().FindAll(userId, m => m.MagicType == MagicType.MoFaZhen && m.MagicID != new GameUser().UserMagicID); if (userMagicList.Count == 0) { List <MagicInfo> magicInfoList = new ConfigCacheSet <MagicInfo>().FindAll(m => m.MagicType == MagicType.MoFaZhen && m.DemandLv <= userLv); foreach (var magicInfo in magicInfoList) { var userMagic = new GameDataCacheSet <UserMagic>().FindKey(userId, magicInfo.MagicID); if (userMagic != null) { continue; } userMagic = new UserMagic { UserID = userId, MagicID = magicInfo.MagicID, MagicLv = magicInfo.MagicLv, MagicType = magicInfo.MagicType, IsEnabled = false }; new GameDataCacheSet <UserMagic>().Add(userMagic); MagicLvInfo magicLvInfo = new ConfigCacheSet <MagicLvInfo>().FindKey(magicInfo.MagicID, magicInfo.MagicLv); short position = magicLvInfo.GetFirstGrid(); var userEmbattle = new UserEmbattle { UserID = userId, GeneralID = 0, // LanguageManager.GetLang().GameUserGeneralID, MagicID = magicInfo.MagicID, Position = position }; new GameDataCacheSet <UserEmbattle>().Add(userEmbattle); } } //UserEmbattle }
protected override void ProcessFriend() { if (!CanCast) { return; } if (Target != null) { UserMagic magic = GetMagic(Spell.MagicShield); if (CanUseMagic(magic) && !HasBuff(BuffType.MagicShield)) { BeginMagic(magic.Spell, Direction, ObjectID, CurrentLocation); return; } magic = GetMagic(Spell.MagicBooster); if (CanUseMagic(magic) && !HasBuff(BuffType.MagicBooster)) { BeginMagic(magic.Spell, Direction, ObjectID, CurrentLocation); return; } } }
public override bool TakeAction() { if (magicType == 0) { userMagicArray = new GameDataCacheSet <UserMagic>().FindAll(ContextUser.UserID).GetPaging(pageIndex, pageSize, out pageCount); } else { userMagicArray = new GameDataCacheSet <UserMagic>().FindAll(ContextUser.UserID, m => m.MagicType == magicType).GetPaging(pageIndex, pageSize, out pageCount); //List<UserMagic> tempList = new List<UserMagic>(userMagicArray); //userMagicArray = tempList.FindAll(m => m.MagicID != new GameUser().UserMagicID); } userMagicArray.ForEach(obj => { obj.IsOpen = true; }); if (magicType == MagicType.MoFaZhen) { var cacheSetMagic = new ConfigCacheSet <MagicInfo>(); var magicList = cacheSetMagic.FindAll(s => s.MagicType == MagicType.MoFaZhen && s.DemandLv > ContextUser.UserLv); magicList.ForEach(mgic => { if (userMagicArray.Find(s => s.MagicID == mgic.MagicID) == null) { UserMagic userMagic = new UserMagic(); userMagic.IsOpen = mgic.DemandLv <= ContextUser.UserLv ? true : false; userMagic.MagicID = mgic.MagicID; userMagic.UserID = string.Empty; userMagic.MagicLv = 0; userMagic.MagicType = MagicType.MoFaZhen; userMagic.IsLv = mgic.DemandLv; userMagicArray.Add(userMagic); } }); } pageCount = MathUtils.Subtraction(pageCount, 1, 0); //List<UserQueue> userQueueArray = new GameDataCacheSet<UserQueue>().FindAll(ContextUser.UserID, m => m.QueueType == QueueType.MagicStrong); //if (userQueueArray.Count > 0 && userQueueArray[0].StrengNum >= 2) //{ // queueID = userQueueArray[0].QueueID; // coldTime = userQueueArray[0].DoRefresh(); //} userMagicArray.QuickSort((x, y) => { if (x == null && y == null) { return(0); } if (x != null && y == null) { return(1); } if (x == null) { return(-1); } return(x.MagicID.CompareTo(y.MagicID)); }); ////记录操作日志 //UserOperationLog userOperationLog = new UserOperationLog(); //userOperationLog.UserID = ContextUser.UserID; //userOperationLog.ActionID = ActionIDDefine.Cst_Action1501; //userOperationLog.FunctionID = "魔术列表"; //userOperationLog.CreateDate = DateTime.Now; //userOperationLog.Num = 1; //userOperationLog.Append(); return(true); }
public override void UseItem(ulong id) { S.UseItem p = new S.UseItem { UniqueID = id, Grid = MirGridType.HeroInventory, Success = false }; UserItem item = null; int index = -1; for (int i = 0; i < Info.Inventory.Length; i++) { item = Info.Inventory[i]; if (item == null || item.UniqueID != id) { continue; } index = i; break; } if (item == null || index == -1 || !CanUseItem(item)) { Owner.Enqueue(p); return; } if (Dead && !(item.Info.Type == ItemType.Scroll && item.Info.Shape == 6)) { Owner.Enqueue(p); return; } switch (item.Info.Type) { case ItemType.Potion: switch (item.Info.Shape) { case 0: //NormalPotion PotHealthAmount = (ushort)Math.Min(ushort.MaxValue, PotHealthAmount + item.Info.Stats[Stat.HP]); PotManaAmount = (ushort)Math.Min(ushort.MaxValue, PotManaAmount + item.Info.Stats[Stat.MP]); break; case 1: //SunPotion ChangeHP(item.Info.Stats[Stat.HP]); ChangeMP(item.Info.Stats[Stat.MP]); break; case 2: //MysteryWater if (UnlockCurse) { ReceiveChat("You can already unequip a cursed item.", ChatType.Hint); Owner.Enqueue(p); return; } ReceiveChat("You can now unequip a cursed item.", ChatType.Hint); UnlockCurse = true; break; case 3: //Buff { int time = item.Info.Durability; if (item.GetTotal(Stat.MaxDC) > 0) { AddBuff(BuffType.Impact, this, time * Settings.Minute, new Stats { [Stat.MaxDC] = item.GetTotal(Stat.MaxDC) }); } if (item.GetTotal(Stat.MaxMC) > 0) { AddBuff(BuffType.Magic, this, time * Settings.Minute, new Stats { [Stat.MaxMC] = item.GetTotal(Stat.MaxMC) }); } if (item.GetTotal(Stat.MaxSC) > 0) { AddBuff(BuffType.Taoist, this, time * Settings.Minute, new Stats { [Stat.MaxSC] = item.GetTotal(Stat.MaxSC) }); } if (item.GetTotal(Stat.AttackSpeed) > 0) { AddBuff(BuffType.Storm, this, time * Settings.Minute, new Stats { [Stat.AttackSpeed] = item.GetTotal(Stat.AttackSpeed) }); } if (item.GetTotal(Stat.HP) > 0) { AddBuff(BuffType.HealthAid, this, time * Settings.Minute, new Stats { [Stat.HP] = item.GetTotal(Stat.HP) }); } if (item.GetTotal(Stat.MP) > 0) { AddBuff(BuffType.ManaAid, this, time * Settings.Minute, new Stats { [Stat.MP] = item.GetTotal(Stat.MP) }); } if (item.GetTotal(Stat.MaxAC) > 0) { AddBuff(BuffType.Defence, this, time * Settings.Minute, new Stats { [Stat.MaxAC] = item.GetTotal(Stat.MaxAC) }); } if (item.GetTotal(Stat.MaxMAC) > 0) { AddBuff(BuffType.MagicDefence, this, time * Settings.Minute, new Stats { [Stat.MaxMAC] = item.GetTotal(Stat.MaxMAC) }); } if (item.GetTotal(Stat.BagWeight) > 0) { AddBuff(BuffType.BagWeight, this, time * Settings.Minute, new Stats { [Stat.BagWeight] = item.GetTotal(Stat.BagWeight) }); } } break; case 4: //Exp { int time = item.Info.Durability; AddBuff(BuffType.Exp, this, Settings.Minute * time, new Stats { [Stat.ExpRatePercent] = item.GetTotal(Stat.Luck) }); } break; case 5: //Drop { int time = item.Info.Durability; AddBuff(BuffType.Drop, this, Settings.Minute * time, new Stats { [Stat.ItemDropRatePercent] = item.GetTotal(Stat.Luck) }); } break; } break; case ItemType.Scroll: UserItem temp; switch (item.Info.Shape) { case 3: //BenedictionOil if (!TryLuckWeapon()) { Owner.Enqueue(p); return; } break; case 4: //RepairOil temp = Info.Equipment[(int)EquipmentSlot.Weapon]; if (temp == null || temp.MaxDura == temp.CurrentDura) { Owner.Enqueue(p); return; } if (temp.Info.Bind.HasFlag(BindMode.DontRepair)) { Owner.Enqueue(p); return; } temp.MaxDura = (ushort)Math.Max(0, temp.MaxDura - Math.Min(5000, temp.MaxDura - temp.CurrentDura) / 30); temp.CurrentDura = (ushort)Math.Min(temp.MaxDura, temp.CurrentDura + 5000); temp.DuraChanged = false; ReceiveChat("Your weapon has been partially repaired", ChatType.Hint); Owner.Enqueue(new S.ItemRepaired { UniqueID = temp.UniqueID, MaxDura = temp.MaxDura, CurrentDura = temp.CurrentDura }); break; case 5: //WarGodOil temp = Info.Equipment[(int)EquipmentSlot.Weapon]; if (temp == null || temp.MaxDura == temp.CurrentDura) { Owner.Enqueue(p); return; } if (temp.Info.Bind.HasFlag(BindMode.DontRepair) || (temp.Info.Bind.HasFlag(BindMode.NoSRepair))) { Owner.Enqueue(p); return; } temp.CurrentDura = temp.MaxDura; temp.DuraChanged = false; ReceiveChat("Your weapon has been completely repaired", ChatType.Hint); Owner.Enqueue(new S.ItemRepaired { UniqueID = temp.UniqueID, MaxDura = temp.MaxDura, CurrentDura = temp.CurrentDura }); break; case 6: //ResurrectionScroll if (CurrentMap.Info.NoReincarnation) { ReceiveChat(string.Format("Cannot use on this map"), ChatType.System); Owner.Enqueue(p); return; } if (Dead) { MP = Stats[Stat.MP]; Revive(MaxHealth, true); } break; } break; case ItemType.Book: UserMagic magic = new UserMagic((Spell)item.Info.Shape); if (magic.Info == null) { Owner.Enqueue(p); return; } Info.Magics.Add(magic); SendMagicInfo(magic); RefreshStats(); break; case ItemType.Food: temp = Info.Equipment[(int)EquipmentSlot.Mount]; if (temp == null || temp.MaxDura == temp.CurrentDura) { Owner.Enqueue(p); return; } switch (item.Info.Shape) { case 0: temp.MaxDura = (ushort)Math.Max(0, temp.MaxDura - Math.Min(1000, temp.MaxDura - (temp.CurrentDura / 30))); break; case 1: break; } temp.CurrentDura = (ushort)Math.Min(temp.MaxDura, temp.CurrentDura + item.CurrentDura); temp.DuraChanged = false; ReceiveChat("Your mount has been fed.", ChatType.Hint); Owner.Enqueue(new S.ItemRepaired { UniqueID = temp.UniqueID, MaxDura = temp.MaxDura, CurrentDura = temp.CurrentDura }); RefreshStats(); break; case ItemType.Transform: //Transforms { AddBuff(BuffType.Transform, this, (Settings.Second * item.Info.Durability), new Stats(), values: item.Info.Shape); } break; case ItemType.Deco: DecoObject decoOb = new DecoObject { Image = item.Info.Shape, CurrentMap = CurrentMap, CurrentLocation = CurrentLocation, }; CurrentMap.AddObject(decoOb); decoOb.Spawned(); Owner.Enqueue(decoOb.GetInfo()); break; case ItemType.MonsterSpawn: var monsterID = item.Info.Stats[Stat.HP]; var spawnAsPet = item.Info.Shape == 1; var conquestOnly = item.Info.Shape == 2; var monsterInfo = Envir.GetMonsterInfo(monsterID); if (monsterInfo == null) { break; } MonsterObject monster = MonsterObject.GetMonster(monsterInfo); if (monster == null) { break; } if (spawnAsPet) { if (Pets.Count(t => !t.Dead && t.Race != ObjectType.Creature) >= Globals.MaxPets) { ReceiveChat("Maximum number of pets already reached.", ChatType.Hint); Owner.Enqueue(p); return; } monster.Master = this; monster.PetLevel = 0; monster.MaxPetLevel = 7; Pets.Add(monster); } if (conquestOnly) { var con = CurrentMap.GetConquest(CurrentLocation); if (con == null) { ReceiveChat(string.Format("{0} can only be spawned during a conquest.", monsterInfo.GameName), ChatType.Hint); Owner.Enqueue(p); return; } } monster.Direction = Direction; monster.ActionTime = Envir.Time + 5000; if (!monster.Spawn(CurrentMap, Front)) { monster.Spawn(CurrentMap, CurrentLocation); } break; case ItemType.SiegeAmmo: //TODO; break; default: return; } if (item.Count > 1) { item.Count--; } else { Info.Inventory[index] = null; } RefreshBagWeight(); Report?.ItemChanged(item, 1, 1); p.Success = true; Owner.Enqueue(p); }
public override void SendMagicInfo(UserMagic magic) { Owner.Enqueue(magic.GetInfo(true)); }