Beispiel #1
0
        }   // end of XmlLevelData WriteToXml()

        protected GameActor ActorFromString(string actorName)
        {
            GameActor ret = null;

            var staticActor = ActorManager.GetActor(actorName);

            if (staticActor == null)
            {
                var splitName  = actorName.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var nsQualName = splitName[0];
                splitName   = nsQualName.Split('.');
                actorName   = splitName[splitName.Length - 1];
                staticActor = ActorManager.GetActor(actorName);
            }

            if (staticActor != null)
            {
                ret = ActorFactory.Create(staticActor);
            }
            else
            {
                Debug.Assert(false, "Why can't find the actor for: '" + actorName + "'!!");
            }

            return(ret);
        }
Beispiel #2
0
    private void OnActorRemoveReply(byte[] bytes)
    {
        ActorRemoveReply input = ActorRemoveReply.Parser.ParseFrom(bytes);

        if (!input.Ret)
        {
            string msg = $"销毁Actor失败!{input.ActorId}";
            GameRoomManager.Instance.Log("MSG: OnActorRemoveReply Error - " + msg);
        }
        else
        {
            PanelRoomMain.Instance.RemoveSelection(input.ActorId); // 如果该单位被选中,要取消选中
            if (input.DieType == 0)
            {                                                      // 自然死亡, 部队解散
                GameRoomManager.Instance.HexmapHelper.DestroyUnit(input.ActorId);
                string msg = $"成功解散部队!{input.ActorId}";
                GameRoomManager.Instance.Log("MSG: OnActorRemoveReply - OK " + msg);
            }
            else if (input.DieType == 1)
            { // 战斗致死, 这时候先不删除该单元,而是要等动画结束以后再删除
                var ab = ActorManager.GetActor(input.ActorId);
                if (ab == null)
                {
                    return;
                }
                ab.StateMachine.TriggerTransition(StateEnum.DIE);
                GameRoomManager.Instance.Log($"MSG: OnActorRemoveReply - OK - {ab.Name}:{ab.ActorId} 被杀死!");
            }
        }
    }
Beispiel #3
0
    private void OnActorAiState(SocketAsyncEventArgs args, byte[] bytes)
    {
        ActorAiState input = ActorAiState.Parser.ParseFrom(bytes);

        if (input.RoomId != RoomId)
        {
            return; // 不是自己房间的消息,略过
        }
        if (input.AiCellIndexFrom == 0)
        {
            string msg = $"Actor position is lost!";
            ServerRoomManager.Instance.Log("RoomLogic OnActorAiState Error - " + msg);
            ActorAiStateReply output2 = new ActorAiStateReply()
            {
                RoomId  = input.RoomId,
                OwnerId = input.OwnerId,
                ActorId = input.ActorId,
                Ret     = false,
                ErrMsg  = msg,
            };

            ServerRoomManager.Instance.SendMsg(args, ROOM_REPLY.ActorAiStateReply, output2.ToByteArray());
            return;
        }

        // 更新单元Ai信息,在服务器的ActorBehaviour里保存一份
        var ab = ActorManager.GetActor(input.ActorId);

        if (ab != null)
        {
            ab.AiState        = input.AiState;
            ab.CellIndex      = input.AiCellIndexFrom;
            ab.AiCellIndexTo  = input.AiCellIndexTo;
            ab.AiTargetId     = input.AiTargetId;
            ab.Orientation    = input.Orientation;
            ab.AiDurationTime = input.AiDurationTime;
            ab.AiTotalTime    = input.AiTotalTime;
            ab.AiStartTime    = DateTime.Now; // 记录得到当前状态的时间, 在存盘的时候再记录一下时间, 把剩余时间保存起来
        }

        // 注意: 有一种情况, 可能是ab并不存在,但是这条消息还是有用的,因为ActorRemoveReply消息里, 服务器已经把本单元删掉了,
        // 但是服务器仍然需要转发一条将单位状态设置为StateEnum.DIE的消息
        ActorAiStateReply output = new ActorAiStateReply()
        {
            RoomId          = input.RoomId,
            OwnerId         = input.OwnerId,
            ActorId         = input.ActorId,
            AiState         = input.AiState,
            AiCellIndexFrom = input.AiCellIndexFrom,
            AiCellIndexTo   = input.AiCellIndexTo,
            AiTargetId      = input.AiTargetId,
            Orientation     = input.Orientation,
            AiDurationTime  = input.AiDurationTime,
            AiTotalTime     = input.AiTotalTime,
            Ret             = true,
        };

        BroadcastMsg(ROOM_REPLY.ActorAiStateReply, output.ToByteArray());
    }
        /// <summary>
        /// Generate a castle as an intersection.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="first"></param>
        /// <param name="second"></param>
        /// <returns></returns>
        public override bool NewFan(
            Road.Intersection isect,
            Road.Section first,
            Road.Section second,
            List <Road.RenderObj> fans)
        {
            bool didBase = base.NewFan(isect, first, second, fans);

            WayPoint.Node node = isect.Node;

            /*
             * centerheight
             * 4.4
             * height
             * 4.3, 2.0, 2.3, 2.3, -1.0
             * width
             * 0.05, 0.2, 0.2, 0.3, 0.3
             * */
            RoadFBXRenderObj ro    = null;
            FBXModel         model = ActorManager.GetActor("Castle").Model;

            if (model != null)
            {
                ro = new RoadFBXRenderObj();

                ro.Model = model;

                Matrix  localToWorld = Matrix.Identity;
                Vector3 position     = node.Position;
                localToWorld.Translation = position;
                ro.LocalToWorld          = localToWorld;

                fans.Add(ro);

                return(true);
            }
            return(didBase);
        }
Beispiel #5
0
        }   // RegisterInCardSpace()

        static public NamedFilter RegisterInCardSpace(string userDefinedName, string nonLocalizedName)
        {
            // Do we already have a filter with this name?
            // If so, don't try and add a new one.
            string filterUPID = "filter.named." + userDefinedName + "." + nonLocalizedName;
            Filter f;

            CardSpace.Cards.FilterDict.TryGetValue(filterUPID, out f);
            if (f != null)
            {
                return(f as NamedFilter);
            }

            NamedFilter namedFilter = new NamedFilter(userDefinedName, nonLocalizedName);

            CardSpace.Cards.FilterDict.Add(namedFilter.upid, namedFilter);

            // Look for a filter tile matching this actor's default name. If found, use its icon for this creatable tile.
            StaticActor actor      = ActorManager.GetActor(nonLocalizedName);
            string      filterName = actor.MenuTextureFile;
            string      iconName;
            Filter      filter = CardSpace.Cards.GetFilter(filterName);

            if (filter != null)
            {
                iconName = filter.TextureName;
            }
            else
            {
                iconName = namedFilter.icon;
            }

            CardSpace.Cards.CacheCardFace(namedFilter.upid, iconName, namedFilter.label, namedFilter.noLabelIcon);

            return(namedFilter);
        } // end of RegisterInCardSpace()
Beispiel #6
0
            // c'tor
            public Shared(MainMenu parent)
            {
                // Set up the options menu.
                optionsMenu = new OptionsMenu();
                liveFeed    = new LiveFeedDisplay();

                if (BokuGame.bMarsMode)
                {
                    boku = ActorManager.GetActor("RoverGreeter").CreateNewInstance() as BokuGreeter;
                }
                else
                {
                    boku = ActorManager.GetActor("BokuGreeter").CreateNewInstance() as BokuGreeter;
                }
                boku.SetColor(Classification.Colors.White);

                bokuCamera.NearClip = 0.1f;
                bokuCamera.FarClip  = 20.0f;
                // These are the values for the model when its translation off the ground has been thrown away (and added back via constant)
                bokuCamera.From = 1.3f * new Vector3(1.5f, 0.3f, 0.5f);
                bokuCamera.At   = new Vector3(0.0f, -0.5f, 0.0f);
                // These are the values for a "correct" model - that is raised off the ground in Max and whose translation is intact
                // bokuCamera.From = new Vector3(1.5f, 0.3f, 1.4f);
                // bokuCamera.At = new Vector3(0.0f, -0.5f, 0.7f);

                // Move camera to look at menu from an angle.
                //camera.From = 0.9f * camera.From;
                camera.At = new Vector3(-0.6f, 0, 0);
                Matrix foo = Matrix.CreateRotationY(-0.3f) * Matrix.CreateTranslation(new Vector3(1.0f, 0.0f, -2.0f));

                camera.At   = Vector3.Transform(camera.At, foo);
                camera.From = Vector3.Transform(camera.From, foo);

                // We'll be using a 1280x720 rendertarget for all rendering.
                camera.Resolution     = new Point(1280, 720);
                bokuCamera.Resolution = new Point(1280, 720);

                timer = new Boku.Base.GameTimer(Boku.Base.GameTimer.ClockType.WallClock, 3.1415927);
                timer.TimerElapsed += ChangeExpression;

                // Create text elements.
                // Start with a blob of common parameters.
                UIGridElement.ParamBlob blob = new UIGridElement.ParamBlob();
                blob.width            = 3.4f;
                blob.height           = 0.5f;
                blob.edgeSize         = 0.06f;
                blob.Font             = UI2D.Shared.GetGameFont24Bold;
                blob.textColor        = Color.White;
                blob.dropShadowColor  = Color.Black;
                blob.useDropShadow    = true;
                blob.invertDropShadow = true;
                blob.unselectedColor  = new Color(new Vector3(4, 100, 90) / 255.0f);
                blob.selectedColor    = new Color(new Vector3(5, 180, 160) / 255.0f);
                blob.normalMapName    = @"Slant0Smoothed5NormalMap";
                blob.justify          = UIGrid2DTextElement.Justification.Left;

                menu             = new ModularMenu(blob, null /*Strings.Localize("mainMenu.mainMenu")*/);
                menu.OnSelect    = parent.OnSelect;
                menu.OnCancel    = parent.OnCancel;
                menu.UseRtCoords = true;


                menu.AddText(Strings.Localize("mainMenu.new"));
                menu.AddText(Strings.Localize("mainMenu.play"));
#if NETFX_CORE
                menu.AddText(Strings.Localize("mainMenu.import"));
#else
                if (WinStoreHelpers.RunningAsUWP)
                {
                    menu.AddText(Strings.Localize("mainMenu.import"));
                }
#endif
                menu.AddText(Strings.Localize("mainMenu.community"));
                menu.AddText(Strings.Localize("mainMenu.options"));
                menu.AddText(Strings.Localize("mainMenu.help"));
#if !NETFX_CORE
                // Once you run an app in Win8, you are never allowed to kill it.
                // Only the system can kill it.
                menu.AddText(Strings.Localize("mainMenu.exit"));
#endif

                // And then remove what we don't want.
                if (!Program2.SiteOptions.CommunityEnabled)
                {
                    menu.DeleteText(Strings.Localize("mainMenu.community"));
                }

                menu.WorldMatrix = Matrix.CreateScale(0.9f, 1.0f, 1.0f);

                string signOutStr = Strings.Localize("textDialog.signOut");
                signOutButton = new Button(signOutStr, Color.White, null, UI2D.Shared.GetGameFont20);

                //Because this button has no texture and we can't set the width of the texture passed in explicitly. Just use the fixed size based on text size.
                UI2D.Shared.GetFont Font = UI2D.Shared.GetGameFont20;
                Vector2             size = (null != Font) ? Font().MeasureString(signOutStr) : new Vector2(60.0f, 20.0f);
                signOutButton.FixedSize    = size;
                signOutButton.UseFixedSize = true;

                textBlob = new TextBlob(UI2D.Shared.GetGameFont24, "", 340);
            }   // end of Shared c'tor
Beispiel #7
0
 static private CruiseMissile NextAvailable()
 {
     return(ActorFactory.Create(ActorManager.GetActor("CruiseMissile")) as CruiseMissile);
 }
            public void AddUISelector(List <GameObject> childList, out UiSelector uiSelector, bool ignorePaths)
            {
                //
                // Set up the pie menu for choosing new objects to add to the scene.
                //
                uiSelector = new PieSelector(null, "Sim.EditObjects.PickThing");

                // Size used for all items.
                Vector2 size = new Vector2(1.0f, 1.0f);

                // Boku
                var boku = ActorManager.GetActor("BokuBot");

                uiSelector.AddItem(new ActorMenuItem(uiSelector, boku.LocalizedName, boku.MenuTextureFile, boku, size, radialOffset));

                // Rover
                var rover = ActorManager.GetActor("Rover");

                uiSelector.AddItem(new ActorMenuItem(uiSelector, rover.LocalizedName, rover.MenuTextureFile, rover, size, radialOffset));

                // Fruit
                var fruit = ActorManager.GetActor("Fruit");

                uiSelector.AddItem(new ActorMenuItem(uiSelector, fruit.LocalizedName, fruit.MenuTextureFile, fruit, size, radialOffset));

                #region BotGroup1
                {
                    RenderObject group = new ActorMenuItem(uiSelector, null, @"Textures\Tiles\group.botsI", null, size, radialOffset);

                    UiSelector selectorGroup = new PieSelector(group, "Sim.EditObjects.PickToken");

                    // move it out front
                    ITransform transformSelector = selectorGroup as ITransform;
                    transformSelector.Local.Translation = new Vector3(0.0f, 0.0f, sizeMenuItem);
                    transformSelector.Compose();

                    selectorGroup.ComposeDefault += NewItemSelectorComposeDefault;
                    selectorGroup.Select         += SelectNewItemSelector;
                    selectorGroup.Cancel         += CancelNewItemSelector;

                    uiSelector.AddGroup(group, selectorGroup);

                    // bot group items

                    var actors = ActorManager.GetActorsInGroup("BotGroup1");
                    for (int i = 0; i < actors.Count; i++)
                    {
                        selectorGroup.AddItem(new ActorMenuItem(selectorGroup, actors[i].LocalizedName, actors[i].MenuTextureFile, actors[i], size, groupRadialOffset));
                    }
                }
                #endregion

                #region BotGroup2
                // some might think a subroutine would be a better way to structure this...
                {
                    RenderObject group = new ActorMenuItem(uiSelector, null, @"Textures\Tiles\group.botsII", null, size, radialOffset);

                    UiSelector selectorGroup = new PieSelector(group, "Sim.EditObjects.PickToken");

                    // move it out front
                    ITransform transformSelector = selectorGroup as ITransform;
                    transformSelector.Local.Translation = new Vector3(0.0f, 0.0f, sizeMenuItem);
                    transformSelector.Compose();

                    selectorGroup.ComposeDefault += NewItemSelectorComposeDefault;
                    selectorGroup.Select         += SelectNewItemSelector;
                    selectorGroup.Cancel         += CancelNewItemSelector;

                    uiSelector.AddGroup(group, selectorGroup);

                    // bot group items
                    var actors = ActorManager.GetActorsInGroup("BotGroup2");
                    for (int i = 0; i < actors.Count; i++)
                    {
                        selectorGroup.AddItem(new ActorMenuItem(selectorGroup, actors[i].LocalizedName, actors[i].MenuTextureFile, actors[i], size, groupRadialOffset));
                    }
                }
                #endregion

                #region objects group (star, coin, heart)
                {
                    RenderObject group = new ActorMenuItem(uiSelector, null, @"Textures\Tiles\group.objects", null, size, radialOffset);

                    UiSelector selectorGroup = new PieSelector(group, "Sim.EditObjects.PickToken");

                    // move it out front
                    ITransform transformSelector = selectorGroup as ITransform;
                    transformSelector.Local.Translation = new Vector3(0.0f, 0.0f, sizeMenuItem);
                    transformSelector.Compose();

                    selectorGroup.ComposeDefault += NewItemSelectorComposeDefault;
                    selectorGroup.Select         += SelectNewItemSelector;
                    selectorGroup.Cancel         += CancelNewItemSelector;

                    uiSelector.AddGroup(group, selectorGroup);


                    var actors = ActorManager.GetActorsInGroup("ObjectGroup");
                    for (int i = 0; i < actors.Count; i++)
                    {
                        selectorGroup.AddItem(new ActorMenuItem(selectorGroup, actors[i].LocalizedName, actors[i].MenuTextureFile, actors[i], size, groupRadialOffset));
                    }
                }

                #endregion

                #region trees group
                // trees group
                //
                {
                    RenderObject group = new ActorMenuItem(uiSelector, null, @"filter.tree", null, size, radialOffset);

                    UiSelector selectorGroup = new PieSelector(group, "Sim.EditObjects.PickTree");

                    // move it out front
                    ITransform transformSelector = selectorGroup as ITransform;
                    transformSelector.Local.Translation = new Vector3(0.0f, 0.0f, sizeMenuItem);
                    transformSelector.Compose();

                    selectorGroup.ComposeDefault += NewItemSelectorComposeDefault;
                    selectorGroup.Select         += SelectNewItemSelector;
                    selectorGroup.Cancel         += CancelNewItemSelector;

                    uiSelector.AddGroup(group, selectorGroup);

                    // Trees group items
                    var actors = ActorManager.GetActorsInGroup("TreeGroup");
                    for (int i = 0; i < actors.Count; i++)
                    {
                        selectorGroup.AddItem(new ActorMenuItem(selectorGroup, actors[i].LocalizedName, actors[i].MenuTextureFile, actors[i], size, groupRadialOffset));
                    }
                }
                #endregion

                #region pipe group
                {
                    RenderObject group = new ActorMenuItem(uiSelector, null, @"filter.pipe", null, size, radialOffset);

                    UiSelector selectorGroup = new PieSelector(group, "Sim.EditObjects.PickPipe");

                    // move it out front
                    ITransform transformSelector = selectorGroup as ITransform;
                    transformSelector.Local.Translation = new Vector3(0.0f, 0.0f, sizeMenuItem);
                    transformSelector.Compose();

                    selectorGroup.ComposeDefault += NewItemSelectorComposeDefault;
                    selectorGroup.Select         += SelectNewItemSelector;
                    selectorGroup.Cancel         += CancelNewItemSelector;

                    uiSelector.AddGroup(group, selectorGroup);

                    // Trees group items
                    var actors = ActorManager.GetActorsInGroup("PipeGroup");
                    for (int i = 0; i < actors.Count; i++)
                    {
                        selectorGroup.AddItem(new ActorMenuItem(selectorGroup, actors[i].LocalizedName, actors[i].MenuTextureFile, actors[i], size, groupRadialOffset));
                    }
                }
                #endregion

                #region underwater group
                // underwater group
                //
                {
                    RenderObject group = new ActorMenuItem(uiSelector, null, @"filter.underwater", null, size, radialOffset);

                    UiSelector selectorGroup = new PieSelector(group, "Sim.EditObjects.PickUnderwater");

                    // move it out front
                    ITransform transformSelector = selectorGroup as ITransform;
                    transformSelector.Local.Translation = new Vector3(0.0f, 0.0f, sizeMenuItem);
                    transformSelector.Compose();

                    selectorGroup.ComposeDefault += NewItemSelectorComposeDefault;
                    selectorGroup.Select         += SelectNewItemSelector;
                    selectorGroup.Cancel         += CancelNewItemSelector;

                    uiSelector.AddGroup(group, selectorGroup);

                    // Trees group items
                    var actors = ActorManager.GetActorsInGroup("UnderwaterGroup");
                    for (int i = 0; i < actors.Count; i++)
                    {
                        selectorGroup.AddItem(new ActorMenuItem(selectorGroup, actors[i].LocalizedName, actors[i].MenuTextureFile, actors[i], size, groupRadialOffset));
                    }
                }
                #endregion

                #region rock group
                // rock group
                //
                {
                    var          rock  = ActorManager.GetActor("Rock");
                    RenderObject group = new ActorMenuItem(uiSelector, rock.LocalizedName, @"filter.rock", null, size, radialOffset);

                    UiSelector selectorGroup = new PieSelector(group, "Sim.EditObjects.PickRock");

                    // move it out front
                    ITransform transformSelector = selectorGroup as ITransform;
                    transformSelector.Local.Translation = new Vector3(0.0f, 0.0f, sizeMenuItem);
                    transformSelector.Compose();

                    selectorGroup.ComposeDefault += NewItemSelectorComposeDefault;
                    selectorGroup.Select         += SelectNewItemSelector;
                    selectorGroup.Cancel         += CancelNewItemSelector;

                    uiSelector.AddGroup(group, selectorGroup);

                    // Trees group items
                    var actors = ActorManager.GetActorsInGroup("RockGroup");
                    for (int i = 0; i < actors.Count; i++)
                    {
                        selectorGroup.AddItem(new ActorMenuItem(selectorGroup, actors[i].LocalizedName, actors[i].MenuTextureFile, actors[i], size, groupRadialOffset));
                    }
                }
                #endregion

                // WayPoint
                #region waypoint group
                if (!ignorePaths)
                {
                    RenderObject group = new ActorMenuItem(uiSelector, null, @"Textures\Tiles\modifier.waypointwhite", null, size, radialOffset);

                    UiSelector selectorGroup = new PieSelector(group, "Sim.EditObjects.PickToken");

                    ITransform transformSelector = selectorGroup as ITransform;
                    transformSelector.Local.Translation = new Vector3(0.0f, 0.0f, sizeMenuItem);
                    transformSelector.Compose();

                    selectorGroup.ComposeDefault += NewItemSelectorComposeDefault;
                    selectorGroup.Select         += SelectNewItemSelector;
                    selectorGroup.Cancel         += CancelNewItemSelector;

                    uiSelector.AddGroup(group, selectorGroup);

                    selectorGroup.AddItem(new ActorMenuItem(selectorGroup, Strings.Localize("actorNames.pathGeneric"), @"filter.pathplain", null, size, radialOffset));
                    selectorGroup.AddItem(new ActorMenuItem(selectorGroup, Strings.Localize("actorNames.pathRoad"), @"filter.pathroad", null, size, radialOffset));
                    selectorGroup.AddItem(new ActorMenuItem(selectorGroup, Strings.Localize("actorNames.pathWall"), @"filter.pathwall", null, size, radialOffset));
                    selectorGroup.AddItem(new ActorMenuItem(selectorGroup, Strings.Localize("actorNames.pathVeggie"), @"filter.pathflora", null, size, radialOffset));

                    //uiSelector.AddItem(new ActorMenuItem(uiSelector, Strings.Localize("actorNames.wayPoint"), null, @"modifier.waypointwhite", null, size, radialOffset));

                    // move the selector into position
                    {
                        //ITransform transformSelector = uiSelector as ITransform;
                        //transformSelector.Local.RotationY = MathHelper.ToRadians(14.0f);
                        //transformSelector.Local.RotationX = MathHelper.ToRadians(14.0f);
                        //transformSelector.Compose();
                    }
                    // Add the selector to the child list.
                }
                #endregion waypoint group

                uiSelector.ComposeDefault += NewItemSelectorComposeDefault;
                uiSelector.Select         += SelectNewItemSelector;
                uiSelector.Cancel         += CancelNewItemSelector;
                childList.Add(uiSelector);
            }   // end of AddUISelector()
Beispiel #9
0
 public Actor GetActor(ActorId id)
 {
     return(ActorManager.GetActor(id));
 }