public SConnection(TcpClient client) : base(client) { IPAddress = client.Client.RemoteEndPoint.ToString().Split(':')[0]; SessionID = ++SessionCount; Language = (StringMessages)ConfigReader.ConfigObjects[typeof(EnglishMessages)]; //Todo Language Selections OnException += (o, e) => { SEnvir.Log(string.Format("Crashed: Account: {0}, Character: {1}.", Account?.EMailAddress, Player?.Name)); SEnvir.Log(e.ToString()); SEnvir.Log(e.StackTrace.ToString()); File.AppendAllText(@".\Errors.txt", e.StackTrace + Environment.NewLine); }; SEnvir.Log(string.Format("[Connection] IP Address:{0}", IPAddress)); UpdateTimeOut(); BeginReceive(); Enqueue(new G.Connected()); }
public bool CanGainItems(bool checkWeight, params ItemCheck[] checks) { int index = 0; foreach (ItemCheck check in checks) { if ((check.Flags & UserItemFlags.QuestItem) == UserItemFlags.QuestItem) { continue; } if (!FilterCompanionPicks(check)) { return(false); } long count = check.Count; if (check.Info.Effect == ItemEffect.Experience) { continue; } if (SEnvir.IsCurrencyItem(check.Info)) { continue; } if (checkWeight) { switch (check.Info.ItemType) { case ItemType.Amulet: case ItemType.Poison: if (BagWeight + check.Info.Weight > Stats[Stat.CompanionBagWeight]) { return(false); } break; default: if (BagWeight + check.Info.Weight * count > Stats[Stat.CompanionBagWeight]) { return(false); } break; } } if (check.Info.StackSize > 1 && (check.Flags & UserItemFlags.Expirable) != UserItemFlags.Expirable) { foreach (UserItem oldItem in Inventory) { if (oldItem == null) { continue; } if (oldItem.Info != check.Info || oldItem.Count >= check.Info.StackSize) { continue; } if ((oldItem.Flags & UserItemFlags.Expirable) == UserItemFlags.Expirable) { continue; } if ((oldItem.Flags & UserItemFlags.Bound) != (check.Flags & UserItemFlags.Bound)) { continue; } if ((oldItem.Flags & UserItemFlags.Worthless) != (check.Flags & UserItemFlags.Worthless)) { continue; } if ((oldItem.Flags & UserItemFlags.NonRefinable) != (check.Flags & UserItemFlags.NonRefinable)) { continue; } if (!oldItem.Stats.Compare(check.Stats)) { continue; } count -= check.Info.StackSize - oldItem.Count; if (count <= 0) { break; } } if (count <= 0) { break; } } //Start Index for (int i = index; i < Stats[Stat.CompanionInventory]; i++) { index++; UserItem item = Inventory[i]; if (item == null) { count -= check.Info.StackSize; if (count <= 0) { break; } } } if (count > 0) { return(false); } } return(true); }
public static void StartWebServer(bool log = true) { if (!Config.EnableWebServer) { return; } try { WebCommandQueue = new ConcurrentQueue <WebCommand>(); WebListener = new HttpListener(); WebListener.Prefixes.Add(Config.WebPrefix); WebListener.Start(); WebListener.BeginGetContext(WebConnection, null); BuyListener = new HttpListener(); BuyListener.Prefixes.Add(Config.BuyPrefix); IPNListener = new HttpListener(); IPNListener.Prefixes.Add(Config.IPNPrefix); BuyListener.Start(); BuyListener.BeginGetContext(BuyConnection, null); IPNListener.Start(); IPNListener.BeginGetContext(IPNConnection, null); WebServerStarted = true; if (log) { SEnvir.Log("Web Server Started."); } } catch (Exception ex) { WebServerStarted = false; SEnvir.Log(ex.ToString()); if (WebListener != null && WebListener.IsListening) { WebListener?.Stop(); } WebListener = null; if (BuyListener != null && BuyListener.IsListening) { BuyListener?.Stop(); } BuyListener = null; if (IPNListener != null && IPNListener.IsListening) { IPNListener?.Stop(); } IPNListener = null; } }
private static void IPNConnection(IAsyncResult result) { const string LiveURL = @"https://ipnpb.paypal.com/cgi-bin/webscr"; const string verified = "VERIFIED"; try { if (IPNListener == null || !IPNListener.IsListening) { return; } HttpListenerContext context = IPNListener.EndGetContext(result); string rawMessage; using (StreamReader readStream = new StreamReader(context.Request.InputStream, Encoding.UTF8)) rawMessage = readStream.ReadToEnd(); Task.Run(() => { string data = "cmd=_notify-validate&" + rawMessage; HttpWebRequest wRequest = (HttpWebRequest)WebRequest.Create(LiveURL); wRequest.Method = "POST"; wRequest.ContentType = "application/x-www-form-urlencoded"; wRequest.ContentLength = data.Length; using (StreamWriter writer = new StreamWriter(wRequest.GetRequestStream(), Encoding.ASCII)) writer.Write(data); using (StreamReader reader = new StreamReader(wRequest.GetResponse().GetResponseStream())) { IPNMessage message = new IPNMessage { Message = rawMessage, Verified = reader.ReadToEnd() == verified }; if (!Directory.Exists(VerifiedPath)) { Directory.CreateDirectory(VerifiedPath); } if (!Directory.Exists(InvalidPath)) { Directory.CreateDirectory(InvalidPath); } string path = (message.Verified ? VerifiedPath : InvalidPath) + Path.GetRandomFileName(); File.WriteAllText(path, message.Message); message.FileName = path; Messages.Enqueue(message); } }); context.Response.StatusCode = (int)HttpStatusCode.OK; context.Response.Close(); } catch (Exception ex) { SEnvir.Log(ex.ToString()); } finally { if (IPNListener != null && IPNListener.IsListening) //IsBound ? { IPNListener.BeginGetContext(IPNConnection, null); } } }
private void DoActions(PlayerObject ob, NPCPage page) { foreach (NPCAction action in page.Actions) { switch (action.ActionType) { case NPCActionType.Teleport: if (action.MapParameter1 == null && action.InstanceParameter1 == null) { return; } if (action.InstanceParameter1 != null) { if (ob.CurrentMap.Instance != null) { return; } var index = SEnvir.LoadInstance(action.InstanceParameter1); if (index == null) { return; } ob.Teleport(action.InstanceParameter1.ConnectRegion, action.InstanceParameter1, index.Value); } else { Map map = SEnvir.GetMap(action.MapParameter1); if (action.IntParameter1 == 0 && action.IntParameter2 == 0) { ob.Teleport(map, map.GetRandomLocation()); } else { ob.Teleport(map, new Point(action.IntParameter1, action.IntParameter2)); } } break; case NPCActionType.TakeGold: ob.Gold.Amount -= action.IntParameter1; ob.GoldChanged(); break; case NPCActionType.ChangeElement: UserItem weapon = ob.Equipment[(int)EquipmentSlot.Weapon]; S.ItemStatsChanged result = new S.ItemStatsChanged { GridType = GridType.Equipment, Slot = (int)EquipmentSlot.Weapon, NewStats = new Stats() }; result.NewStats[Stat.WeaponElement] = action.IntParameter1 - weapon.Stats[Stat.WeaponElement]; weapon.AddStat(Stat.WeaponElement, action.IntParameter1 - weapon.Stats[Stat.WeaponElement], StatSource.Refine); weapon.StatsChanged(); ob.RefreshStats(); ob.Enqueue(result); break; case NPCActionType.ChangeHorse: ob.Character.Account.Horse = (HorseType)action.IntParameter1; ob.RemoveMount(); ob.RefreshStats(); if (ob.Character.Account.Horse != HorseType.None) { ob.Mount(); } break; case NPCActionType.GiveGold: long gold = ob.Gold.Amount + action.IntParameter1; ob.Gold.Amount = (long)gold; ob.GoldChanged(); break; case NPCActionType.Marriage: ob.MarriageRequest(); break; case NPCActionType.Divorce: ob.MarriageLeave(); break; case NPCActionType.RemoveWeddingRing: ob.MarriageRemoveRing(); break; case NPCActionType.GiveItem: if (action.ItemParameter1 == null) { continue; } ItemCheck check = new ItemCheck(action.ItemParameter1, action.IntParameter1, UserItemFlags.None, TimeSpan.Zero); if (!ob.CanGainItems(false, check)) { continue; } while (check.Count > 0) { ob.GainItem(SEnvir.CreateFreshItem(check)); } break; case NPCActionType.TakeItem: if (action.ItemParameter1 == null) { continue; } ob.TakeItem(action.ItemParameter1, action.IntParameter1); break; case NPCActionType.ResetWeapon: ob.NPCResetWeapon(); break; case NPCActionType.GiveItemExperience: if (action.ItemParameter1 == null) { continue; } check = new ItemCheck(action.ItemParameter1, action.IntParameter1, UserItemFlags.None, TimeSpan.Zero); if (!ob.CanGainItems(false, check)) { continue; } while (check.Count > 0) { UserItem item = SEnvir.CreateFreshItem(check); item.Experience = action.IntParameter2; if (item.Experience >= Globals.AccessoryExperienceList[item.Level]) { item.Experience -= Globals.AccessoryExperienceList[item.Level]; item.Level++; item.Flags |= UserItemFlags.Refinable; } ob.GainItem(item); } break; case NPCActionType.SpecialRefine: ob.NPCSpecialRefine(action.StatParameter1, action.IntParameter1); break; case NPCActionType.Rebirth: if (ob.Level >= 86 + ob.Character.Rebirth) { ob.NPCRebirth(); } break; case NPCActionType.GiveCurrency: { if (action.StringParameter1 == null) { continue; } var info = SEnvir.CurrencyInfoList.Binding.FirstOrDefault(x => string.Equals(x.Name, action.StringParameter1, StringComparison.OrdinalIgnoreCase)); if (info == null) { continue; } var userCurrency = ob.GetCurrency(info); var amount = userCurrency.Amount + action.IntParameter1; userCurrency.Amount = amount; ob.CurrencyChanged(userCurrency); } break; case NPCActionType.TakeCurrency: { if (action.StringParameter1 == null) { continue; } var info = SEnvir.CurrencyInfoList.Binding.FirstOrDefault(x => string.Equals(x.Name, action.StringParameter1, StringComparison.OrdinalIgnoreCase)); if (info == null) { continue; } var userCurrency = ob.GetCurrency(info); var amount = userCurrency.Amount - action.IntParameter1; userCurrency.Amount = amount; ob.CurrencyChanged(userCurrency); } break; } } }
public override void Process() { base.Process(); if (SEnvir.Now >= DespawnTime) { if (SpawnInfo != null) { SpawnInfo.AliveCount--; } foreach (SConnection con in SEnvir.Connections) { con.ReceiveChat(con.Language.LairGateClosed, MessageType.System); } SpawnInfo = null; Despawn(); return; } if (SEnvir.Now >= SearchTime && SEnvir.LairMapRegion != null && SEnvir.LairMapRegion.PointList.Count > 0) { SearchTime = SEnvir.Now.AddSeconds(3); Map map = SEnvir.GetMap(SEnvir.LairMapRegion.Map); if (map == null) { SearchTime = SEnvir.Now.AddSeconds(60); return; } for (int i = CurrentMap.Objects.Count - 1; i >= 0; i--) { MapObject ob = CurrentMap.Objects[i]; if (ob == this) { continue; } if (ob is Guard) { continue; } switch (ob.Race) { case ObjectType.Player: if (ob.InSafeZone) { continue; } if (ob.Dead || !Functions.InRange(ob.CurrentLocation, CurrentLocation, MonsterInfo.ViewRange)) { continue; } ob.Teleport(map, SEnvir.LairMapRegion.PointList[SEnvir.Random.Next(SEnvir.LairMapRegion.PointList.Count)]); break; default: continue; } } } }
public Cell GetMovement(MapObject ob) { if (Movements == null || Movements.Count == 0) { return(this); } for (int i = 0; i < 5; i++) //20 Attempts to get movement; { MovementInfo movement = Movements[SEnvir.Random.Next(Movements.Count)]; Map map = SEnvir.GetMap(movement.DestinationRegion.Map, Map.Instance, Map.InstanceIndex); Cell cell = map.GetCell(movement.DestinationRegion.PointList[SEnvir.Random.Next(movement.DestinationRegion.PointList.Count)]); if (cell == null) { continue; } if (ob.Race == ObjectType.Player) { bool allowed = true; PlayerObject player = (PlayerObject)ob; if (movement.DestinationRegion.Map.MinimumLevel > ob.Level && !player.Character.Account.TempAdmin) { player.Connection.ReceiveChat(string.Format(player.Connection.Language.NeedLevel, movement.DestinationRegion.Map.MinimumLevel), MessageType.System); foreach (SConnection con in player.Connection.Observers) { con.ReceiveChat(string.Format(con.Language.NeedLevel, movement.DestinationRegion.Map.MinimumLevel), MessageType.System); } break; } if (movement.DestinationRegion.Map.MaximumLevel > 0 && movement.DestinationRegion.Map.MaximumLevel < ob.Level && !player.Character.Account.TempAdmin) { player.Connection.ReceiveChat(string.Format(player.Connection.Language.NeedMaxLevel, movement.DestinationRegion.Map.MaximumLevel), MessageType.System); foreach (SConnection con in player.Connection.Observers) { con.ReceiveChat(string.Format(con.Language.NeedMaxLevel, movement.DestinationRegion.Map.MaximumLevel), MessageType.System); } break; } if (movement.DestinationRegion.Map.RequiredClass != RequiredClass.None && movement.DestinationRegion.Map.RequiredClass != RequiredClass.All) { switch (player.Class) { case MirClass.Warrior: if ((movement.DestinationRegion.Map.RequiredClass & RequiredClass.Warrior) != RequiredClass.Warrior) { allowed = false; } break; case MirClass.Wizard: if ((movement.DestinationRegion.Map.RequiredClass & RequiredClass.Wizard) != RequiredClass.Wizard) { allowed = false; } break; case MirClass.Taoist: if ((movement.DestinationRegion.Map.RequiredClass & RequiredClass.Taoist) != RequiredClass.Taoist) { allowed = false; } break; case MirClass.Assassin: if ((movement.DestinationRegion.Map.RequiredClass & RequiredClass.Assassin) != RequiredClass.Assassin) { allowed = false; } break; } if (!allowed) { var message = string.Format(player.Connection.Language.NeedClass, movement.DestinationRegion.Map.RequiredClass.ToString()); player.Connection.ReceiveChat(message, MessageType.System); foreach (SConnection con in player.Connection.Observers) { con.ReceiveChat(message, MessageType.System); } break; } } if (movement.NeedSpawn != null) { SpawnInfo spawn = SEnvir.Spawns.FirstOrDefault(x => x.Info == movement.NeedSpawn); if (spawn == null) { break; } if (spawn.AliveCount == 0) { player.Connection.ReceiveChat(player.Connection.Language.NeedMonster, MessageType.System); foreach (SConnection con in player.Connection.Observers) { con.ReceiveChat(con.Language.NeedMonster, MessageType.System); } break; } } if (movement.NeedItem != null) { if (player.GetItemCount(movement.NeedItem) == 0) { player.Connection.ReceiveChat(string.Format(player.Connection.Language.NeedItem, movement.NeedItem.ItemName), MessageType.System); foreach (SConnection con in player.Connection.Observers) { con.ReceiveChat(string.Format(con.Language.NeedItem, movement.NeedItem.ItemName), MessageType.System); } break; } player.TakeItem(movement.NeedItem, 1); } foreach (UserQuest quest in player.Character.Quests) { //For Each Active Quest if (quest.Completed) { continue; } bool changed = false; foreach (QuestTask task in quest.QuestInfo.Tasks) { if (task.Task != QuestTaskType.Region || task.RegionParameter == null) { continue; } if (task.RegionParameter != movement.SourceRegion) { continue; } UserQuestTask userTask = quest.Tasks.FirstOrDefault(x => x.Task == task); if (userTask == null) { userTask = SEnvir.UserQuestTaskList.CreateNewObject(); userTask.Task = task; userTask.Quest = quest; } if (userTask.Completed) { continue; } userTask.Amount = 1; changed = true; } if (changed) { player.Enqueue(new S.QuestChanged { Quest = quest.ToClientInfo() }); } } switch (movement.Effect) { case MovementEffect.SpecialRepair: player.SpecialRepair(EquipmentSlot.Weapon); player.SpecialRepair(EquipmentSlot.Shield); player.SpecialRepair(EquipmentSlot.Helmet); player.SpecialRepair(EquipmentSlot.Armour); player.SpecialRepair(EquipmentSlot.Necklace); player.SpecialRepair(EquipmentSlot.BraceletL); player.SpecialRepair(EquipmentSlot.BraceletR); player.SpecialRepair(EquipmentSlot.RingL); player.SpecialRepair(EquipmentSlot.RingR); player.SpecialRepair(EquipmentSlot.Shoes); player.RefreshStats(); break; } } return(cell.GetMovement(ob)); } return(this); }
public void Load() { string fileName = Info.FileName; if (fileName.Contains("|")) { fileName = fileName.Split('|')[1]; } fileName = $"{Config.MapPath}{fileName}.map"; if (!File.Exists(fileName)) { SEnvir.Log($"Map: {fileName} not found."); return; } byte[] fileBytes = File.ReadAllBytes(fileName); int offSet = 0; Width = BitConverter.ToInt16(fileBytes, offSet); offSet += 2; Height = BitConverter.ToInt16(fileBytes, offSet); Cells = new Cell[Width, Height]; //DoorIndex = new Door[Width, Height]; offSet = 52; for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) {//total 12 bool isWall = (BitConverter.ToInt16(fileBytes, offSet) & 0x8000) != 0; offSet += 2; if ((BitConverter.ToInt16(fileBytes, offSet) & 0x8000) != 0) { isWall = true; } offSet += 2; if ((BitConverter.ToInt16(fileBytes, offSet) & 0x8000) != 0) { isWall = true; } if (!isWall) { ValidCells.Add(Cells[x, y] = new Cell(new Point(x, y)) { Map = this }); } offSet += 4; //if (fileBytes[offSet] > 0) // DoorIndex[x, y] = AddDoor(fileBytes[offSet], new Point(x, y)); offSet += 3; byte light = fileBytes[offSet++]; //if (light >= 100 && light <= 119) // Cells[x, y].FishingAttribute = (sbyte)(light - 100); } } OrderedObjects = new HashSet <MapObject> [Width]; for (int i = 0; i < OrderedObjects.Length; i++) { OrderedObjects[i] = new HashSet <MapObject>(); } }
private void ImportBtn_ItemClick(object sender, ItemClickEventArgs e) { var collection = SMain.Session.GetCollection <MonsterInfo>(); var dropCollection = SMain.Session.GetCollection <DropInfo>(); var itemCollection = SMain.Session.GetCollection <ItemInfo>(); using (var reader = new StreamReader("AmzData/Monster.csv")) using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) { csv.Read(); csv.ReadHeader(); while (csv.Read()) { var name = csv.GetField("Name"); if (name.StartsWith("=") || collection.Binding.Any(m => m.MonsterName == name)) { continue; } var monster = collection.CreateNewObject(); monster.MonsterName = name; monster.Image = MonsterImage.Scarecrow; monster.AI = 0; monster.Level = csv.GetField <int>("Lvl"); monster.ViewRange = 9; monster.CoolEye = csv.GetField <int>("CoolEye"); monster.Experience = csv.GetField <int>("Exp"); monster.Undead = csv.GetField <bool>("Undead"); monster.CanPush = true; monster.CanTame = true; monster.IsBoss = false; monster.Flag = MonsterFlag.None; monster.AttackDelay = csv.GetField <int>("ATTACK_SPD"); monster.MoveDelay = csv.GetField <int>("WALK_SPD"); if (File.Exists($"AmzData/MonItems/{name}.txt")) { var dropList = File.ReadAllLines($"AmzData/MonItems/{name}.txt", Encoding.GetEncoding("GB2312")); for (var index = 0; index < dropList.Length; index++) { var s = dropList[index]; if (string.IsNullOrEmpty(s)) { continue; } if (s.StartsWith("#")) { continue; } if (s.StartsWith("(")) { while (s != ")") { s = dropList[index++]; } s = dropList[index]; } var info = s.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); if (info.Length < 2) { continue; } var item = itemCollection.Binding.FirstOrDefault(i => i.ItemName == info[1]); if (item == null) { SEnvir.Log($"item not found: {info[1]}"); continue; } var drop = dropCollection.CreateNewObject(); drop.Monster = monster; drop.Item = item; if (info.Length == 3) { drop.Amount = int.Parse(info[2]); } else { drop.Amount = 1; } drop.Chance = int.Parse(info[0].Replace("1/", "")); drop.DropSet = 0; drop.PartOnly = false; drop.EasterEvent = false; monster.Drops.Add(drop); } } } } }
public override void Die() { if (War != null) { if (EXPOwner?.Node == null) { return; } if (EXPOwner.Character.Account.GuildMember == null) { return; } if (EXPOwner.Character.Account.GuildMember.Guild.Castle != null) { return; } if (War.Participants.Count > 0 && !War.Participants.Contains(EXPOwner.Character.Account.GuildMember.Guild)) { return; } #region Conquest Stats UserConquestStats conquest = SEnvir.GetConquestStats((PlayerObject)EXPOwner); if (conquest != null) { conquest.BossKillCount++; } #endregion GuildInfo ownerGuild = SEnvir.GuildInfoList.Binding.FirstOrDefault(x => x.Castle == War.Castle); if (ownerGuild != null) { ownerGuild.Castle = null; } EXPOwner.Character.Account.GuildMember.Guild.Castle = War.Castle; foreach (SConnection con in SEnvir.Connections) { con.ReceiveChat(string.Format(con.Language.ConquestCapture, EXPOwner.Character.Account.GuildMember.Guild.GuildName, War.Castle.Name), MessageType.System); } SEnvir.Broadcast(new S.GuildCastleInfo { Index = War.Castle.Index, Owner = EXPOwner.Character.Account.GuildMember.Guild.GuildName }); War.CastleBoss = null; War.PingPlayers(); War.SpawnBoss(); if (War.EndTime - SEnvir.Now < TimeSpan.FromMinutes(15)) { War.EndTime = SEnvir.Now.AddMinutes(15); } foreach (PlayerObject player in SEnvir.Players) { player.ApplyCastleBuff(); } War = null; } base.Die(); }
public override long Attacked(MapObject attacker, long power, Element element, bool canReflect = true, bool ignoreShield = false, bool canCrit = true, bool canStruck = true) { if (attacker == null || attacker.Race != ObjectType.Player) { return(0); } PlayerObject player = (PlayerObject)attacker; if (War == null) { return(0); } if (player.Character.Account.GuildMember == null) { return(0); } if (player.Character.Account.GuildMember.Guild.Castle != null) { return(0); } if (War.Participants.Count > 0 && !War.Participants.Contains(player.Character.Account.GuildMember.Guild)) { return(0); } long result = base.Attacked(attacker, 1, element, canReflect, ignoreShield, canCrit); #region Conquest Stats switch (attacker.Race) { case ObjectType.Player: UserConquestStats conquest = SEnvir.GetConquestStats((PlayerObject)attacker); if (conquest != null) { conquest.BossDamageDealt += result; } break; case ObjectType.Monster: MonsterObject mob = (MonsterObject)attacker; if (mob.PetOwner != null) { conquest = SEnvir.GetConquestStats(mob.PetOwner); if (conquest != null) { conquest.BossDamageDealt += result; } } break; } #endregion EXPOwner = null; return(result); }
public Cell GetMovement(MapObject ob) { if (Movements == null || Movements.Count == 0) { return(this); } for (int i = 0; i < 5; i++) //20 Attempts to get movement; { MovementInfo movement = Movements[SEnvir.Random.Next(Movements.Count)]; Map map = SEnvir.GetMap(movement.DestinationRegion.Map); Cell cell = map.GetCell(movement.DestinationRegion.PointList[SEnvir.Random.Next(movement.DestinationRegion.PointList.Count)]); if (cell == null) { continue; } if (ob.Race == ObjectType.Player) { PlayerObject player = (PlayerObject)ob; if (movement.DestinationRegion.Map.MinimumLevel > ob.Level && !player.Character.Account.TempAdmin) { player.Connection.ReceiveChat(string.Format(player.Connection.Language.NeedLevel, movement.DestinationRegion.Map.MinimumLevel), MessageType.System); foreach (SConnection con in player.Connection.Observers) { con.ReceiveChat(string.Format(con.Language.NeedLevel, movement.DestinationRegion.Map.MinimumLevel), MessageType.System); } break; } if (movement.DestinationRegion.Map.MaximumLevel > 0 && movement.DestinationRegion.Map.MaximumLevel < ob.Level && !player.Character.Account.TempAdmin) { player.Connection.ReceiveChat(string.Format(player.Connection.Language.NeedMaxLevel, movement.DestinationRegion.Map.MaximumLevel), MessageType.System); foreach (SConnection con in player.Connection.Observers) { con.ReceiveChat(string.Format(con.Language.NeedMaxLevel, movement.DestinationRegion.Map.MaximumLevel), MessageType.System); } break; } if (movement.NeedSpawn != null) { SpawnInfo spawn = SEnvir.Spawns.FirstOrDefault(x => x.Info == movement.NeedSpawn); if (spawn == null) { break; } if (spawn.AliveCount == 0) { player.Connection.ReceiveChat(player.Connection.Language.NeedMonster, MessageType.System); foreach (SConnection con in player.Connection.Observers) { con.ReceiveChat(con.Language.NeedMonster, MessageType.System); } break; } } if (movement.NeedItem != null) { if (player.GetItemCount(movement.NeedItem) == 0) { player.Connection.ReceiveChat(string.Format(player.Connection.Language.NeedItem, movement.NeedItem.ItemName), MessageType.System); foreach (SConnection con in player.Connection.Observers) { con.ReceiveChat(string.Format(con.Language.NeedItem, movement.NeedItem.ItemName), MessageType.System); } break; } player.TakeItem(movement.NeedItem, 1); } switch (movement.Effect) { case MovementEffect.SpecialRepair: player.SpecialRepair(EquipmentSlot.Weapon); player.SpecialRepair(EquipmentSlot.Shield); player.SpecialRepair(EquipmentSlot.Helmet); player.SpecialRepair(EquipmentSlot.Armour); player.SpecialRepair(EquipmentSlot.Necklace); player.SpecialRepair(EquipmentSlot.BraceletL); player.SpecialRepair(EquipmentSlot.BraceletR); player.SpecialRepair(EquipmentSlot.RingL); player.SpecialRepair(EquipmentSlot.RingR); player.SpecialRepair(EquipmentSlot.Shoes); player.RefreshStats(); break; } } return(cell.GetMovement(ob)); } return(this); }
public void Load() { string fileName = $"{Config.MapPath}{Info.FileName}.map"; if (!File.Exists(fileName)) { SEnvir.Log($"Map: {fileName} not found."); return; } byte[] fileBytes = File.ReadAllBytes(fileName); /*Width = fileBytes[23] << 8 | fileBytes[22]; * Height = fileBytes[25] << 8 | fileBytes[24]; * * Cells = new Cell[Width, Height]; * * int offSet = 28 + Width * Height / 4 * 3; * * for (int x = 0; x < Width; x++) * for (int y = 0; y < Height; y++) * { * byte flag = fileBytes[offSet + (x * Height + y) * 14]; * * if ((flag & 0x02) != 2 || (flag & 0x01) != 1) continue; * * ValidCells.Add(Cells[x, y] = new Cell(new Point(x, y)) { Map = this }); * }*/ switch (FindType(fileBytes)) { case 0: LoadMapCellsv0(fileBytes); break; case 1: LoadMapCellsv1(fileBytes); break; case 2: LoadMapCellsv2(fileBytes); break; case 3: LoadMapCellsv3(fileBytes); break; case 4: LoadMapCellsv4(fileBytes); break; case 5: LoadMapCellsv5(fileBytes); break; case 6: LoadMapCellsv6(fileBytes); break; case 7: LoadMapCellsv7(fileBytes); break; case 100: LoadMapCellsV100(fileBytes); break; } OrderedObjects = new HashSet <MapObject> [Width]; for (int i = 0; i < OrderedObjects.Length; i++) { OrderedObjects[i] = new HashSet <MapObject>(); } }
public void GainItem(params UserItem[] items) { CompanionOwner.Enqueue(new S.CompanionItemsGained { Items = items.Where(x => x.Info.Effect != ItemEffect.Experience).Select(x => x.ToClientInfo()).ToList() }); HashSet <UserQuest> changedQuests = new HashSet <UserQuest>(); foreach (UserItem item in items) { if (item.UserTask != null) { if (item.UserTask.Completed) { continue; } item.UserTask.Amount = Math.Min(item.UserTask.Task.Amount, item.UserTask.Amount + item.Count); changedQuests.Add(item.UserTask.Quest); if (item.UserTask.Completed) { for (int i = item.UserTask.Objects.Count - 1; i >= 0; i--) { item.UserTask.Objects[i].Despawn(); } } item.UserTask = null; item.Flags &= ~UserItemFlags.QuestItem; item.IsTemporary = true; item.Delete(); continue; } if (SEnvir.IsCurrencyItem(item.Info)) { var currency = CompanionOwner.GetCurrency(item.Info); currency.Amount += item.Count; item.IsTemporary = true; item.Delete(); continue; } if (item.Info.Effect == ItemEffect.Experience) { CompanionOwner.GainExperience(item.Count, false); item.IsTemporary = true; item.Delete(); continue; } bool handled = false; if (item.Info.StackSize > 1 && (item.Flags & UserItemFlags.Expirable) != UserItemFlags.Expirable) { foreach (UserItem oldItem in Inventory) { if (oldItem == null || oldItem.Info != item.Info || oldItem.Count >= oldItem.Info.StackSize) { continue; } if ((oldItem.Flags & UserItemFlags.Expirable) == UserItemFlags.Expirable) { continue; } if ((oldItem.Flags & UserItemFlags.Bound) != (item.Flags & UserItemFlags.Bound)) { continue; } if ((oldItem.Flags & UserItemFlags.Worthless) != (item.Flags & UserItemFlags.Worthless)) { continue; } if ((oldItem.Flags & UserItemFlags.NonRefinable) != (item.Flags & UserItemFlags.NonRefinable)) { continue; } if (!oldItem.Stats.Compare(item.Stats)) { continue; } if (oldItem.Count + item.Count <= item.Info.StackSize) { oldItem.Count += item.Count; item.IsTemporary = true; item.Delete(); handled = true; break; } item.Count -= item.Info.StackSize - oldItem.Count; oldItem.Count = item.Info.StackSize; } if (handled) { continue; } } for (int i = 0; i < Stats[Stat.CompanionInventory]; i++) { if (Inventory[i] != null) { continue; } Inventory[i] = item; item.Slot = i; item.Companion = UserCompanion; item.IsTemporary = false; break; } } foreach (UserQuest quest in changedQuests) { CompanionOwner.Enqueue(new S.QuestChanged { Quest = quest.ToClientInfo() }); } RefreshStats(); }
public override void Process() { base.Process(); if (Owner != null && (Owner.Node == null || Owner.Dead)) { Despawn(); return; } if (SEnvir.Now < TickTime) { return; } if (TickCount-- <= 0) { switch (Effect) { case SpellEffect.SwordOfVengeance: PlayerObject player = Owner as PlayerObject; if (player == null) { break; } List <Cell> cells = CurrentMap.GetCells(CurrentLocation, 0, 3); foreach (Cell cell in cells) { if (cell.Objects != null) { for (int i = cell.Objects.Count - 1; i >= 0; i--) { if (i >= cell.Objects.Count) { continue; } MapObject target = cell.Objects[i]; if (!player.CanAttackTarget(target)) { continue; } int damage = player.MagicAttack(new List <UserMagic> { Magic }, target, true); ActionList.Add(new DelayedAction( SEnvir.Now.AddMilliseconds(500), ActionType.DelayMagic, new List <UserMagic> { Magic }, target)); } } } break; case SpellEffect.MonsterDeathCloud: MonsterObject monster = Owner as MonsterObject; if (monster == null) { break; } for (int i = CurrentCell.Objects.Count - 1; i >= 0; i--) { if (i >= CurrentCell.Objects.Count) { continue; } MapObject ob = CurrentCell.Objects[i]; if (!monster.CanAttackTarget(ob)) { continue; } monster.Attack(ob, 4000, Element.None); monster.Attack(ob, 4000, Element.None); } break; } Despawn(); return; } TickTime = SEnvir.Now + TickFrequency; switch (Effect) { case SpellEffect.TrapOctagon: for (int i = Targets.Count - 1; i >= 0; i--) { MapObject ob = Targets[i]; if (ob.Node != null && ob.ShockTime != DateTime.MinValue) { continue; } Targets.Remove(ob); } if (Targets.Count == 0) { Despawn(); } break; default: if (CurrentCell == null) { SEnvir.Log($"[ERROR] {Effect} CurrentCell Null."); return; } if (CurrentCell.Objects == null) { SEnvir.Log($"[ERROR] {Effect} CurrentCell.Objects Null."); return; } for (int i = CurrentCell.Objects.Count - 1; i >= 0; i--) { if (i >= CurrentCell.Objects.Count) { continue; } if (CurrentCell.Objects[i] == this) { continue; } ProcessSpell(CurrentCell.Objects[i]); if (CurrentCell == null) { SEnvir.Log($"[ERROR] {Effect} CurrentCell Null Loop."); return; } if (CurrentCell.Objects == null) { SEnvir.Log($"[ERROR] {Effect} CurrentCell.Objects Null Loop."); return; } } break; } }
public SpawnInfo(RespawnInfo info) { Info = info; CurrentMap = SEnvir.GetMap(info.Region.Map); LastCheck = SEnvir.Now; }
public override void Process() { base.Process(); if (Owner != null && (Owner.Node == null || Owner.Dead)) { Despawn(); return; } if (SEnvir.Now < TickTime) { return; } if (TickCount-- <= 0) { switch (Effect) { case SpellEffect.MonsterDeathCloud: MonsterObject monster = Owner as MonsterObject; if (monster == null) { break; } for (int i = CurrentCell.Objects.Count - 1; i >= 0; i--) { if (i >= CurrentCell.Objects.Count) { continue; } MapObject ob = CurrentCell.Objects[i]; if (!monster.CanAttackTarget(ob)) { continue; } monster.Attack(ob, 4000, Element.None); monster.Attack(ob, 4000, Element.None); } break; } Despawn(); return; } TickTime = SEnvir.Now + TickFrequency; switch (Effect) { case SpellEffect.TrapOctagon: for (int i = Targets.Count - 1; i >= 0; i--) { MapObject ob = Targets[i]; if (ob.Node != null && ob.ShockTime != DateTime.MinValue) { continue; } Targets.Remove(ob); } if (Targets.Count == 0) { Despawn(); } break; default: if (CurrentCell == null) { SEnvir.Log($"[ERROR] {Effect} CurrentCell Null."); return; } if (CurrentCell.Objects == null) { SEnvir.Log($"[ERROR] {Effect} CurrentCell.Objects Null."); return; } for (int i = CurrentCell.Objects.Count - 1; i >= 0; i--) { if (i >= CurrentCell.Objects.Count) { continue; } if (CurrentCell.Objects[i] == this) { continue; } ProcessSpell(CurrentCell.Objects[i]); if (CurrentCell == null) { SEnvir.Log($"[ERROR] {Effect} CurrentCell Null Loop."); return; } if (CurrentCell.Objects == null) { SEnvir.Log($"[ERROR] {Effect} CurrentCell.Objects Null Loop."); return; } } break; } }
public SpawnInfo(RespawnInfo info, InstanceInfo instance, byte index) { Info = info; CurrentMap = SEnvir.GetMap(info.Region.Map, instance, index); LastCheck = SEnvir.Now; }
public void EndWar() { foreach (SConnection con in SEnvir.Connections) { con.ReceiveChat(string.Format(con.Language.ConquestFinished, Castle.Name), MessageType.System); } Ended = true; for (int i = Map.NPCs.Count - 1; i >= 0; i--) { NPCObject npc = Map.NPCs[i]; // if (!Castle.CastleRegion.PointList.Contains(npc.CurrentLocation)) continue; npc.Visible = true; npc.AddAllObjects(); } PingPlayers(); DespawnBoss(); SEnvir.ConquestWars.Remove(this); SEnvir.Broadcast(new S.GuildConquestFinished { Index = Castle.Index }); GuildInfo ownerGuild = SEnvir.GuildInfoList.Binding.FirstOrDefault(x => x.Castle == Castle); if (ownerGuild != null) { foreach (SConnection con in SEnvir.Connections) { con.ReceiveChat(string.Format(con.Language.ConquestOwner, ownerGuild.GuildName, Castle.Name), MessageType.System); } UserConquest conquest = SEnvir.UserConquestList.Binding.FirstOrDefault(x => x.Castle == Castle && x.Castle == ownerGuild?.Castle); TimeSpan warTime = TimeSpan.MinValue; if (conquest != null) { warTime = (conquest.WarDate + conquest.Castle.StartTime) - SEnvir.Now; } foreach (GuildMemberInfo member in ownerGuild.Members) { if (member.Account.Connection?.Player == null) { continue; //Offline } member.Account.Connection.Enqueue(new S.GuildConquestDate { Index = Castle.Index, WarTime = warTime, ObserverPacket = false }); } } foreach (GuildInfo participant in Participants) { if (participant == ownerGuild) { continue; } foreach (GuildMemberInfo member in participant.Members) { if (member.Account.Connection?.Player == null) { continue; //Offline } member.Account.Connection.Enqueue(new S.GuildConquestDate { Index = Castle.Index, WarTime = TimeSpan.MinValue, ObserverPacket = false }); } } }
private void DoActions(PlayerObject ob, NPCPage page) { foreach (NPCAction action in page.Actions) { switch (action.ActionType) { case NPCActionType.Teleport: if (action.MapParameter1 == null) { return; } Map map = SEnvir.GetMap(action.MapParameter1); if (action.IntParameter1 == 0 && action.IntParameter2 == 0) { ob.Teleport(map, map.GetRandomLocation()); } else { ob.Teleport(map, new Point(action.IntParameter1, action.IntParameter2)); } break; case NPCActionType.TakeGold: ob.Gold -= action.IntParameter1; ob.GoldChanged(); break; case NPCActionType.ChangeElement: UserItem weapon = ob.Equipment[(int)EquipmentSlot.Weapon]; S.ItemStatsChanged result = new S.ItemStatsChanged { GridType = GridType.Equipment, Slot = (int)EquipmentSlot.Weapon, NewStats = new Stats() }; result.NewStats[Stat.WeaponElement] = action.IntParameter1 - weapon.Stats[Stat.WeaponElement]; weapon.AddStat(Stat.WeaponElement, action.IntParameter1 - weapon.Stats[Stat.WeaponElement], StatSource.Refine); weapon.StatsChanged(); ob.RefreshStats(); ob.Enqueue(result); break; case NPCActionType.ChangeHorse: ob.Character.Account.Horse = (HorseType)action.IntParameter1; ob.RemoveMount(); ob.RefreshStats(); if (ob.Character.Account.Horse != HorseType.None) { ob.Mount(); } break; case NPCActionType.GiveGold: long gold = ob.Gold + action.IntParameter1; ob.Gold = (long)gold; ob.GoldChanged(); break; case NPCActionType.Marriage: ob.MarriageRequest(); break; case NPCActionType.Divorce: ob.MarriageLeave(); break; case NPCActionType.RemoveWeddingRing: ob.MarriageRemoveRing(); break; case NPCActionType.GiveItem: if (action.ItemParameter1 == null) { continue; } ItemCheck check = new ItemCheck(action.ItemParameter1, action.IntParameter1, UserItemFlags.None, TimeSpan.Zero); if (!ob.CanGainItems(false, check)) { continue; } while (check.Count > 0) { ob.GainItem(SEnvir.CreateFreshItem(check)); } break; case NPCActionType.TakeItem: if (action.ItemParameter1 == null) { continue; } ob.TakeItem(action.ItemParameter1, action.IntParameter1); break; case NPCActionType.ResetWeapon: ob.NPCResetWeapon(); break; case NPCActionType.GiveItemExperience: if (action.ItemParameter1 == null) { continue; } check = new ItemCheck(action.ItemParameter1, action.IntParameter1, UserItemFlags.None, TimeSpan.Zero); if (!ob.CanGainItems(false, check)) { continue; } while (check.Count > 0) { UserItem item = SEnvir.CreateFreshItem(check); item.Experience = action.IntParameter2; if (item.Experience >= Globals.AccessoryExperienceList[item.Level]) { item.Experience -= Globals.AccessoryExperienceList[item.Level]; item.Level++; item.Flags |= UserItemFlags.Refinable; } ob.GainItem(item); } break; case NPCActionType.SpecialRefine: ob.NPCSpecialRefine(action.StatParameter1, action.IntParameter1); break; case NPCActionType.Rebirth: if (ob.Level >= 86 + ob.Character.Rebirth) { ob.NPCRebirth(); } break; } } }
private static void SystemDBSync(HttpListenerContext context) { try { if (!Config.AllowSystemDBSync) { SEnvir.Log($"Trying sync but not enabled"); context.Response.StatusCode = 401; return; } if (context.Request.HttpMethod != "POST" || !context.Request.HasEntityBody) { SEnvir.Log($"Trying sync but method is not post or not have body"); context.Response.StatusCode = 401; return; } if (context.Request.ContentLength64 > 1024 * 1024 * 10) { SEnvir.Log($"Trying sync but exceeded SystemDB size"); context.Response.StatusCode = 400; return; } var masterPassword = context.Request.QueryString["Key"]; if (string.IsNullOrEmpty(masterPassword) || !masterPassword.Equals(Config.SyncKey)) { SEnvir.Log($"Trying sync but key received is not valid"); context.Response.StatusCode = 400; return; } SEnvir.Log($"Starting remote syncronization..."); var buffer = new byte[context.Request.ContentLength64]; var offset = 0; var length = 0; var bufferSize = 1024 * 16; while ((length = context.Request.InputStream.Read(buffer, offset, offset + bufferSize > buffer.Length ? buffer.Length - offset : bufferSize)) > 0) { offset += length; } if (SEnvir.Session.BackUp && !Directory.Exists(SEnvir.Session.SystemBackupPath)) { Directory.CreateDirectory(SEnvir.Session.SystemBackupPath); } if (File.Exists(SEnvir.Session.SystemPath)) { if (SEnvir.Session.BackUp) { using (FileStream sourceStream = File.OpenRead(SEnvir.Session.SystemPath)) using (FileStream destStream = File.Create(SEnvir.Session.SystemBackupPath + "System " + SEnvir.Session.ToBackUpFileName(DateTime.UtcNow) + Session.Extension + Session.CompressExtension)) using (GZipStream compress = new GZipStream(destStream, CompressionMode.Compress)) sourceStream.CopyTo(compress); } File.Delete(SEnvir.Session.SystemPath); } File.WriteAllBytes(SEnvir.Session.SystemPath, buffer); context.Response.StatusCode = 200; SEnvir.Log($"Syncronization completed..."); } catch (Exception ex) { context.Response.StatusCode = 500; context.Response.ContentType = "text/plain"; var message = Encoding.UTF8.GetBytes(ex.ToString()); context.Response.OutputStream.Write(message, 0, message.Length); SEnvir.Log("Syncronization exception: " + ex.ToString()); } finally { context.Response.Close(); } }
private void PluginLoader_Log(object sender, PluginCore.LogEventArgs e) { SEnvir.Log(e.Message); }
private void StartServerButton_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { InterfaceTimer.Enabled = true; SEnvir.StartServer(); UpdateInterface(); }