public static Vector3[] GenerateWaypoints(MapId map, Vector3 lastPos)
        {
            ITerrain terrain = TerrainMgr.GetTerrain(map);

            if (terrain != null)
            {
                return(new RandomWaypointGenerator().GenerateWaypoints(terrain, lastPos));
            }
            return(new Vector3[0]);
        }
Beispiel #2
0
 public WorldServerClient(Realm rl, byte[] key)
 {
     mUsername   = Config.Login.ToUpper();
     objectMgr   = new ObjectMgr();
     movementMgr = new MovementMgr(this);
     combatMgr   = new CombatMgr(this);
     terrainMgr  = new TerrainMgr();
     realm       = rl;
     mKey        = key;
 }
Beispiel #3
0
    void Loop()
    {
        while (true)
        {
            try
            {
                Coordinate Waypoint;
                float      angle, dist;

                UInt32 timeNow = MM_GetTime();
                UInt32 diff    = (timeNow - lastUpdateTime);
                lastUpdateTime = timeNow;
                if (Waypoints.Count != 0)
                {
                    Waypoint = Waypoints.First();

                    if (Waypoint != null)
                    {
                        angle = TerrainMgr.CalculateAngle(objectMgr.getPlayerObject().Position, Waypoint);
                        dist  = TerrainMgr.CalculateDistance(objectMgr.getPlayerObject().Position, Waypoint);
                        if (angle == objectMgr.getPlayerObject().Position.O)
                        {
                            if (dist > 1)
                            {
                                Flag.SetMoveFlag(MovementFlags.MOVEMENTFLAG_FORWARD);
                                UpdatePosition(diff);
                                lastUpdateTime = timeNow;
                            }
                            else
                            {
                                Waypoints.Remove(Waypoint);
                            }
                        }
                        else
                        {
                            Flag.SetMoveFlag(MovementFlags.MOVEMENTFLAG_NONE);
                            objectMgr.getPlayerObject().Position.O = angle;
                        }
                    }
                }
                else
                {
                    Flag.Clear();
                    Flag.SetMoveFlag(MovementFlags.MOVEMENTFLAG_NONE);
                }
            }
            catch (Exception ex)
            {
                //Exchange.OnNewLog("Exception Occured");
                //Exchange.OnNewLog("Message: " + ex.Message);
                ///Exchange.OnNewLog("Stacktrace: " + ex.StackTrace);
            }
        }
    }
Beispiel #4
0
 public World(string user, Realm rl, byte[] key)
 {
     mUsername   = user.ToUpper();
     objectMgr   = new ObjectMgr();
     movementMgr = new MovementMgr(this);
     combatMgr   = new CombatMgr(this);
     terrainMgr  = new TerrainMgr();
     realm       = rl;
     mKey        = key;
     PacketQueue = new Queue();
 }
Beispiel #5
0
        public void CreateRandomWaypoints()
        {
            var terrain = TerrainMgr.GetTerrain(MapId);

            if (terrain != null)
            {
                var gen = new RandomWaypointGenerator();
                var wps = gen.GenerateWaypoints(terrain, Position, RespawnRadius);
                AddWaypoints(wps);
                Waypoints.Last.Value.WaitTime = (uint)Utility.Random(2000, 7000);
            }
        }
        public static Vector3[] GenerateWaypoints(MapId map, Vector3 lastPos)
        {
            var terrain = TerrainMgr.GetTerrain(map);

            if (terrain != null)
            {
                var gen = new RandomWaypointGenerator();
                var wps = gen.GenerateWaypoints(terrain, lastPos);
                return(wps);
            }
            return(new Vector3[0]);
        }
Beispiel #7
0
        public void CreateRandomWaypoints()
        {
            ITerrain terrain = TerrainMgr.GetTerrain(MapId);

            if (terrain == null)
            {
                return;
            }
            AddWaypoints(
                new RandomWaypointGenerator().GenerateWaypoints(terrain, Position, RespawnRadius));
            Waypoints.Last.Value.WaitTime = (uint)Utility.Random(2000, 7000);
        }
Beispiel #8
0
 void Loop()
 {
     while (true)
     {
         try
         {
             if (Targets.Count > 0)
             {
                 Object target = Targets.First();
                 float  dist   = TerrainMgr.CalculateDistance(objectMgr.getPlayerObject().Position, target.Position);
                 if (dist > 1)
                 {
                     movementMgr.Waypoints.Add(target.Position);
                 }
                 else if (dist < 1 && !isFighting)
                 {
                     client.Attack(target);
                     isFighting = true;
                 }
                 else if (isFighting && target.Health < 0)
                 {
                     isFighting = false;
                     Targets.Remove(target);
                 }
                 else if (isFighting && target.Health > 0)
                 {
                     Console.WriteLine(target.Health);
                 }
             }
         }
         catch (Exception ex)
         {
             Log.WriteLine(LogType.Error, "Exception Occured");
             Log.WriteLine(LogType.Error, "Message: {0}", ex.Message);
             Log.WriteLine(LogType.Error, "Stacktrace: {0}", ex.StackTrace);
         }
     }
 }
Beispiel #9
0
 void Loop()
 {
     while (true)
     {
         try
         {
             if (Targets.Count > 0)
             {
                 Assets.Scripts.World.Object target = Targets.First();
                 float dist = TerrainMgr.CalculateDistance(objectMgr.getPlayerObject().Position, target.Position);
                 if (dist > 1)
                 {
                     movementMgr.Waypoints.Add(target.Position);
                 }
                 else if (dist < 1 && !isFighting)
                 {
                     //client.Attack(target);
                     isFighting = true;
                 }
                 else if (isFighting && target.Health < 0)
                 {
                     isFighting = false;
                     Targets.Remove(target);
                 }
                 else if (isFighting && target.Health > 0)
                 {
                     Debug.LogWarning(target.Health.ToString());
                 }
             }
         }
         catch (Exception ex)
         {
             Debug.LogWarning("Exception Occured");
             Debug.LogWarning("Message: " + ex.Message);
             Debug.LogWarning("Stacktrace: " + ex.StackTrace);
         }
     }
 }
Beispiel #10
0
        /// <summary>
        /// 分析场景数据
        /// 使用SceneData构建SceneMgr的Item列表
        /// </summary>
        /// <param name="sceneData"></param>
        public void LoadScene(String sceneName)
        {
            // 读取文件
            SceneData sceneData = SceneData.Load(sceneName);

            // 读取背景
            backgroundMgr = new ItemMgr();
            foreach (BackgroundData backgroundData in sceneData.backgroundDataList)
            {
                backgroundMgr.AddItem(new Background(backgroundData));
            }
            

            // 读取场景地板...
            terrainMgr = new TerrainMgr();
            foreach (TerrainData terrainData in sceneData.terrainDataList)
            {
                terrainMgr.AddItem(new Terrain(terrainData));
            }
            foreach (TiledTerrainData tiledTerrainData in sceneData.tiledTerrainDataList)
            {
                terrainMgr.AddItem(new TiledTerrain(tiledTerrainData));
            }

            // 读取位置信息...
            // 包括角色出生点、道具、交互物体、开关触发器、门等等的位置信息...
            // 并关联程序中定义的触发行为 (触发行为包括:获得物品、物理效应、电影模式等等)
            // (另外还有一些非触发行为: 使用道具枪支钩绳,这些部分适合定义在管理器中,而不是角色本身)

            // 读取连协开关...
            // 设定这类对象的关联参数
            // 并关联程序中定义的触发行为

            // 读取动画数据...
            // 包括事件列表
            // 动画的构成包括 -- Item的动态创建、动画、物理效应、固定暂停、角色对话心理、摄像机动画、屏幕特效、音乐切换、音效等等及其组合表现形式

            // 读取前景、等杂项...

            // 读取完毕
        }
Beispiel #11
0
	public void SetTerrainMgr( TerrainMgr mgr )
	{		
		m_terrainMgr = mgr;		
		m_terrainMgr.LoadTable();		
	}
Beispiel #12
0
	// Awake
	void Awake()
	{
		ms_kIstance = this;
	}
Beispiel #13
0
            public override void Process(CmdTrigger <RealmServerCmdArgs> trigger)
            {
                var chr = trigger.Args.Character;

                if (chr == null)
                {
                    trigger.Reply("Character required in context.");
                    return;
                }

                if (!NPCMgr.Loaded)
                {
                    trigger.Reply("Loading NPCs...");
                    NPCMgr.LoadAllLater();
                    return;
                }

                var figurines = TerrainVisualizations.ClearVis(chr);

                var radius  = trigger.Text.NextFloat(30.0f);
                var p       = chr.Position;
                var map     = chr.Map;
                var terrain = TerrainMgr.GetTerrain(map.MapId) as SimpleTerrain;

                if (terrain == null)
                {
                    trigger.Reply("No Terrain created for Map: " + map);
                    return;
                }

                int tileX, tileY;

                PositionUtil.GetTileXYForPos(p, out tileX, out tileY);
                var tile = terrain.GetTile(tileX, tileY);

                if (tile == null || tile.NavMesh == null)
                {
                    trigger.Reply("No NavMesh present on Tile.");
                    return;
                }

                var mesh = tile.NavMesh;

                foreach (var poly in mesh.Polygons)
                {
                    Debug.Assert(poly.Indices.Length == 3);
                    var v1 = mesh.Vertices[poly.Indices[0]];
                    var v2 = mesh.Vertices[poly.Indices[1]];
                    var v3 = mesh.Vertices[poly.Indices[2]];

                    // only get polygons that are narby
                    if (p.GetDistance(ref v1) > radius &&
                        p.GetDistance(ref v2) > radius &&
                        p.GetDistance(ref v3) > radius)
                    {
                        continue;
                    }

                    var dumm1 = new NavFigurine();
                    var dumm2 = new NavFigurine();
                    var dumm3 = new NavFigurine();

                    dumm1.SetOrientationTowards(ref v2);
                    dumm1.ChannelObject = dumm2;
                    map.AddObject(dumm1, ref v1);

                    dumm2.SetOrientationTowards(ref v3);
                    dumm2.ChannelObject = dumm3;
                    map.AddObject(dumm2, ref v2);

                    dumm3.SetOrientationTowards(ref v1);
                    dumm3.ChannelObject = dumm1;
                    map.AddObject(dumm3, ref v3);

                    figurines.Add(dumm1);
                    figurines.Add(dumm2);
                    figurines.Add(dumm3);
                }

                trigger.Reply("Created {0} figurines.", figurines.Count);
            }
Beispiel #14
0
        /// <summary>
        /// 清空场景
        /// </summary>
        public void ResetScene()
        {
            // 重置物理模拟环境
            PhysicsSys.Instance.PhysicsSimulator.Clear();
            // 重置摄像机...

            // 清空ItemMgr
            ClearItemList(); // 过期..
            backgroundMgr = null;
            terrainMgr = null;
            actItemMgr = null;
            role = null;
            forgroundMgr = null;
            
        }
Beispiel #15
0
        protected virtual void Awake()
        {
            Time.timeScale = 1.0f; //unfreeze game if it was frozen from a previous game.

            Initialized = false;   //faction stats are not ready, yet

            //Get components:
            CamMgr           = FindObjectOfType(typeof(CameraController)) as CameraController; //Find the camera movement script.
            ResourceMgr      = FindObjectOfType(typeof(ResourceManager)) as ResourceManager;   //Find the resource manager script.
            BuildingMgr      = FindObjectOfType(typeof(BuildingManager)) as BuildingManager;
            TaskMgr          = FindObjectOfType(typeof(TaskManager)) as TaskManager;
            UnitMgr          = FindObjectOfType(typeof(UnitManager)) as UnitManager;
            SelectionMgr     = FindObjectOfType(typeof(SelectionManager)) as SelectionManager;
            GroupSelection   = FindObjectOfType(typeof(UnitGroupSelection)) as UnitGroupSelection;
            PlacementMgr     = FindObjectOfType(typeof(BuildingPlacement)) as BuildingPlacement;
            TerrainMgr       = FindObjectOfType(typeof(TerrainManager)) as TerrainManager;
            MvtMgr           = FindObjectOfType(typeof(MovementManager)) as MovementManager;
            UIMgr            = FindObjectOfType(typeof(UIManager)) as UIManager; //Find the UI manager script.
            ErrorMessageMgr  = FindObjectOfType(typeof(ErrorMessageHandler)) as ErrorMessageHandler;
            MinimapIconMgr   = FindObjectOfType(typeof(MinimapIconManager)) as MinimapIconManager;
            AttackWarningMgr = FindObjectOfType(typeof(AttackWarningManager)) as AttackWarningManager;
            AttackMgr        = FindObjectOfType(typeof(AttackManager)) as AttackManager;
            EffectPool       = FindObjectOfType(typeof(EffectObjPool)) as EffectObjPool;
            UpgradeMgr       = FindObjectOfType(typeof(UpgradeManager)) as UpgradeManager;
            InputMgr         = FindObjectOfType(typeof(InputManager)) as InputManager;
#if RTSENGINE_FOW
            FoWMgr = FindObjectOfType(typeof(FogOfWarRTSManager)) as FogOfWarRTSManager;
#endif

#if RTSENGINE_FOW
            if (FoWMgr) //only if there's a fog of war manager in the scene
            {
                FoWMgr.Init(this);
            }
#endif

            CamMgr.Init(this);
            MinimapIconMgr?.Init(this);
            MvtMgr.Init(this);
            TaskMgr.Init(this);
            SelectionMgr.Init(this);
            GroupSelection.Init(this);
            PlacementMgr.Init(this);
            TerrainMgr.Init(this);
            UIMgr.Init(this); //initialize the UI manager.
            ErrorMessageMgr.Init(this);
            AttackWarningMgr?.Init(this);
            AttackMgr.Init(this);
            EffectPool.Init(this);
            UpgradeMgr.Init(this);
            ResourceMgr.Init(this);
            BuildingMgr.Init(this);
            UnitMgr.Init(this);
            InputMgr.Init(this);

            MultiplayerGame = false;                               //We start by assuming it's a single player game.

            if (!InitMultiplayerGame() && !InitSinglePlayerGame()) //if it's not neither a multiplayer nor a single player game
            {
                InitFactions();                                    //we're starting the game directly from the editor in the map scene, init factions directly
            }

            ResourceMgr.InitFactionResources();       //init resources for factions.

            InitCampaignGame();                       //initialise a game where the player is coming from the campaign menu to play a mission
            SetPlayerFaction();                       //pick the player faction ID.
            InitDefaultEntities();                    //initialise the pre-spawned faction units and factions

            ResourceMgr.InitResources();              //init the pre-spawned resources.

            UnitMgr.OnFactionSlotsInitialized();      //init free units
            BuildingMgr.OnFactionSlotsInitialized();  //init free buildings
            if (MultiplayerGame)                      //if this is a multiplayer game
            {
                InputMgr.OnFactionSlotsInitialized(); //init spawnable prefabs and default entities in a multiplayer game
            }
            //In order to avoid having buildings that are being placed by AI players and units collide, we will ignore physics between their two layers:
            Physics.IgnoreLayerCollision(LayerMask.NameToLayer("Hidden"), LayerMask.NameToLayer("Unit"));

            //Set the amount of the active factions:
            activefactionsAmount = factions.Count;

            SetGameState(GameState.running);          //the game state is now set to running

            UIMgr.PeaceTime.Toggle(peaceTime > 0.0f); //enable the peace time panel if there's actual peace time assigned

            //reaching this point means that all faction info/stats in the game manager are ready:
            Initialized = true;
        }
Beispiel #16
0
 public MovementMgr(World Client)
 {
     objectMgr  = Client.objectMgr;
     terrainMgr = Client.terrainMgr;
 }
Beispiel #17
0
 public float CalculateDistance(Coordinate c1)
 {
     return(TerrainMgr.CalculateDistance(objectMgr.getPlayerObject().Position, c1));
 }
Beispiel #18
0
            public override void Process(CmdTrigger <RealmServerCmdArgs> trigger)
            {
                MapId mapId;
                int   tileX, tileY;

                if (trigger.Text.HasNext)
                {
                    mapId = trigger.Text.NextEnum(MapId.End);
                    tileX = trigger.Text.NextInt(-1);
                    tileY = trigger.Text.NextInt(-1);
                }
                else if (trigger.Args.Character == null)
                {
                    trigger.Reply("You did not specify map id and tile location.");
                    return;
                }
                else
                {
                    mapId = trigger.Args.Character.MapId;
                    PositionUtil.GetTileXYForPos(trigger.Args.Character.Position, out tileX, out tileY);
                }

                var terrain = TerrainMgr.GetTerrain(mapId);

                if (terrain == null)
                {
                    trigger.Reply("Invalid MapId.");
                    return;
                }

                if (!PositionUtil.VerifyTileCoords(tileX, tileY))
                {
                    trigger.Reply("Invalid tile coordinates.");
                    return;
                }

                trigger.Reply("Loading tile...");
                RealmServer.RealmServer.IOQueue.AddMessage(() =>
                {
                    terrain.ForceLoadTile(tileX, tileY);

                    if (terrain.IsAvailable(tileX, tileY))
                    {
                        trigger.Reply("Done. Tile ({0}, {1}) in Map {2} has been loaded.", tileX, tileY, mapId);
                    }
                    else
                    {
                        // try to extract from MPQ
                        //var adt = ADTReader.ReadADT(terrain, tileX, tileY);
                        trigger.Reply("WARNING: Tile ({0}, {1}) in Map {2} has not been exported yet...", tileX, tileY, mapId);
                        trigger.Reply("Extraction will take a while and block the IO queue, please have patience...");

                        var adt = WDT.LoadTile(mapId, tileX, tileY);
                        if (adt != null)
                        {
                            trigger.Reply("Tile ({0}, {1}) in Map {2} has been imported...", tileX, tileY, mapId);
                            trigger.Reply("Writing to file...");

                            // export to file
                            SimpleTileWriter.WriteADT(adt);

                            // try loading again
                            trigger.Reply("Loading extracted tile and generating Navigation mesh...");
                            terrain.ForceLoadTile(tileX, tileY);

                            if (terrain.IsAvailable(tileX, tileY))
                            {
                                trigger.Reply("Done. Tile ({0}, {1}) in Map {2} has been loaded successfully.", tileX, tileY, mapId);
                                return;
                            }
                        }

                        trigger.Reply("Loading FAILED: Tile ({0}, {1}) in Map {2} could not be loaded", tileX, tileY, mapId);
                    }
                });
            }