private void ControlMessage_SpawnMonster(HybrasylControlMessage message) { var monster = (Monster)message.Arguments[0]; var map = (Map)message.Arguments[1]; GameLog.DebugFormat("monolith: spawning monster {0} on map {1}", monster.Name, map.Name); map.InsertCreature(monster); }
private void ControlMessage_MonolithControl(HybrasylControlMessage message) { var monster = (Monster)message.Arguments[0]; var map = (Map)message.Arguments[1]; // Don't handle control messages for dead/removed mobs, or mobs that cannot move or attack if (!monster.Condition.Alive || monster.DeathProcessed || monster.Id == 0 || monster.Map == null || monster.Condition.Asleep || monster.Condition.Frozen) { return; } monster.NextAction(); }
private void ControlMessage_LogoffUser(HybrasylControlMessage message) { // Log off the specified user var userName = (string)message.Arguments[0]; Logger.WarnFormat("{0}: forcing logoff", userName); User user; if (Users.TryGetValue(userName, out user)) { user.Logoff(); } }
private void ControlMessage_ShutdownServer(HybrasylControlMessage message) { // Initiate an orderly shutdown var userName = (string) message.Arguments[0]; Logger.WarnFormat("Server shutdown request initiated by {0}", userName); // Chaos is Rising Up, yo. foreach (var connection in ActiveUsers) { var user = connection.Value; user.SendMessage("Chaos is rising up. Please re-enter in a few minutes.", Hybrasyl.MessageTypes.SYSTEM_WITH_OVERHEAD); } // Actually shut down the server. This terminates the listener loop in Game. if (Game.IsActive()) Game.ToggleActive(); Logger.WarnFormat("Server has begun shutdown"); }
private void ControlMessage_SaveUser(HybrasylControlMessage message) { // save a user User user; var connectionId = (long) message.Arguments[0]; if (ActiveUsers.TryGetValue(connectionId, out user)) { Logger.DebugFormat("Saving user {0}", user.Name); user.SaveDataToEntityFramework(); } else { Logger.WarnFormat("Tried to save user associated with connection ID {0} but user doesn't exist", connectionId); } }
private void ControlMessage_RegenerateUser(HybrasylControlMessage message) { // regenerate a user // USDA Formula for HP: MAXHP * (0.1 + (CON - Lv) * 0.01) <20% MAXHP // USDA Formula for MP: MAXMP * (0.1 + (WIS - Lv) * 0.01) <20% MAXMP // Regen = regen * 0.0015 (so 100 regen = 15%) User user; var connectionId = (long) message.Arguments[0]; if (ActiveUsers.TryGetValue(connectionId, out user)) { uint hpRegen = 0; uint mpRegen = 0; double fixedRegenBuff = Math.Min(user.Regen*0.0015, 0.15); if (user.Hp != user.MaximumHp) { hpRegen = (uint) Math.Min(user.MaximumHp*(0.1*Math.Max(user.Con, (user.Con - user.Level))*0.01), user.MaximumHp*0.20); hpRegen = hpRegen + (uint) (fixedRegenBuff*user.MaximumHp); } if (user.Mp != user.MaximumMp) { mpRegen = (uint) Math.Min(user.MaximumMp*(0.1*Math.Max(user.Int, (user.Int - user.Level))*0.01), user.MaximumMp*0.20); mpRegen = mpRegen + (uint) (fixedRegenBuff*user.MaximumMp); } Logger.DebugFormat("User {0}: regen HP {1}, MP {2}", user.Name, hpRegen, mpRegen); user.Hp = Math.Min(user.Hp + hpRegen, user.MaximumHp); user.Mp = Math.Min(user.Mp + mpRegen, user.MaximumMp); user.UpdateAttributes(StatUpdateFlags.Current); } }
private void ControlMessage_CleanupUser(HybrasylControlMessage message) { // clean up after a broken connection var connectionId = (long) message.Arguments[0]; User user; if (ActiveUsers.TryRemove(connectionId, out user)) { Logger.InfoFormat("cid {0}: closed, player {1} removed", connectionId, user.Name); if (user.ActiveExchange != null) user.ActiveExchange.CancelExchange(user); ((IDictionary) ActiveUsersByName).Remove(user.Name); user.Save(); user.UpdateLogoffTime(); user.Map.Remove(user); Remove(user); Logger.DebugFormat("cid {0}: {1} cleaned up successfully", user.Name); DeleteUser(user.Name); } }
private void ControlMessage_MonolithControl(HybrasylControlMessage message) { var monster = (Monster)message.Arguments[0]; var map = (Map)message.Arguments[1]; // Don't handle control messages for dead/removed mobs, or mobs that cannot move or attack if (!monster.Condition.Alive || monster.DeathProcessed || monster.Id == 0 || monster.Map == null || monster.Condition.Asleep || monster.Condition.Frozen) { return; } if (monster.IsHostile) { if (map.Users.Count > 0) { var entityTree = map.EntityTree.GetObjects(monster.GetViewport()); //get players on screen var players = entityTree.OfType <User>(); if (players.Count() > 0) { //get closest if (monster.ThreatInfo.ThreatTable.Count == 0) { //get monster.ThreatInfo.AddNewThreat(players.OrderBy(x => x.Distance(monster)).FirstOrDefault(), 1); } } UserGroup targetGroup = null; //get aggro target's group if (monster.ThreatInfo.ThreatTarget != null && monster.ThreatInfo.ThreatTarget is User) { targetGroup = ((User)monster.ThreatInfo.ThreatTarget).Group; } if (monster.ThreatInfo.ThreatTarget != null) { //pathfind or cast if far away if (monster.Distance(monster.ThreatInfo.ThreatTarget) >= 2) { var nextAction = _random.Next(1, 7); if (nextAction > 1) { //pathfind, only if not paralyzed if (!monster.Condition.Paralyzed && !monster.Condition.Blinded) { monster.PathFind((monster.Location.X, monster.Location.Y), (monster.ThreatInfo.ThreatTarget.Location.X, monster.ThreatInfo.ThreatTarget.Location.Y)); } } else { //cast if (!monster.Condition.Blinded) { monster.Cast(monster.ThreatInfo.ThreatTarget, targetGroup); } } } else { //check facing and attack or cast var nextAction = _random.Next(1, 6); if (nextAction > 1) { var facing = monster.CheckFacing(monster.Direction, monster.ThreatInfo.ThreatTarget); if (facing) { monster.AssailAttack(monster.Direction, monster.ThreatInfo.ThreatTarget); } } else { if (!monster.Condition.Blinded) { monster.Cast(monster.ThreatInfo.ThreatTarget, targetGroup); } } } } } } if (monster.ShouldWander) { var nextAction = _random.Next(0, 2); if (nextAction == 1) { var nextMove = _random.Next(0, 4); monster.Walk((Xml.Direction)nextMove); } else { var nextMove = _random.Next(0, 4); monster.Turn((Xml.Direction)nextMove); } } }