protected override void OnReceivedMessage(string message, params object[] args)
        {
            if (message == "get reward")
            {
                var rew = (Reward)args[0];
                if (!rew.Verify())
                {
                    return;
                }

                if (rew.Coin > 0)
                {
                    userData.AddCoin(rew.Coin);
                }
                if (rew.Exp > 0)
                {
                    userData.AddExp(rew.Exp);
                }

                if (rew.Achivement != null && rew.Achivement.Verify() && !userData.Achivements.Exists(ach => ach.Name == rew.Achivement.Name))
                {
                    userData.Achivements.Add(rew.Achivement);
                    MMW.BroadcastMessage("log", $"Archived [{rew.Achivement.Name}]");
                }
            }
        }
        public override void OnTcpReceived(int dataType, byte[] data)
        {
            if (dataType == DataType.PictureChat)
            {
                var chat = Util.DeserializeJsonBinaryCompress <NwPictureChat>(data);

                MMW.BroadcastMessage("picture chat", chat.From, chat.Data);
            }
        }
Exemplo n.º 3
0
        protected override void Update(double deltaTime)
        {
            var cam  = MMW.MainCamera;
            var from = cam.Transform.WorldPosition;
            var to   = from + ((cam.Target - from).Normalized() * Distance);

            rays = Bullet.RayTest(from, to, GameObject);

            var prev = closed;

            closed = null;
            foreach (var r in rays)
            {
                if (r.GameObject.Destroyed)
                {
                    continue;
                }
                closed = r;
                break;
            }

            float rot = 0.0f;

            {
                var t = (cam.Target - from);
                t.Y = 0.0f;
                t.Normalize();
                rot = Vector3.CalculateAngle(-Vector3.UnitZ, t);
                var cross = Vector3.Cross(-Vector3.UnitZ, t);
                rot *= cross.Y >= 0.0f ? -1.0f : 1.0f;
            }

            if (closed != null)
            {
                data.gameobject = closed.GameObject;
                data.position   = closed.Position;
                data.normal     = closed.Normal;
                data.rotate     = new Vector3(0.0f, rot, 0.0f);
                data.distance   = Distance * closed.Rate;
            }

            if (prev == null && closed != null)
            {
                MMW.BroadcastMessage("focus enter", closed.GameObject, data);
            }
            else if (prev != null && closed == null)
            {
                MMW.BroadcastMessage("focus leave", prev.GameObject, data);
            }
            else if (prev != null && closed != null && prev != closed)
            {
                MMW.BroadcastMessage("focus leave", prev.GameObject, data);
                MMW.BroadcastMessage("focus enter", closed.GameObject, data);
            }
        }
Exemplo n.º 4
0
 private void Server_Disconnected(object sender, EventArgs e)
 {
     if (!leave)
     {
         if (inventoryShown)
         {
             MMW.BroadcastMessage("close inventory");
         }
         if (menuShown)
         {
             MMW.BroadcastMessage("close menu");
         }
         MMW.BroadcastMessage("show dialog");
         MMW.BroadcastMessage("show leave window");
     }
 }
Exemplo n.º 5
0
        private void LeavePlayer(WalkerPlayer player)
        {
            MMW.Invoke(() =>
            {
                try
                {
                    Players.Remove(Players.Find(p => (int)p.Properties["sessionID"] == player.SessionID));
                    worldData.Players.Remove(player);

                    MMW.BroadcastMessage("log", $"player \"{player.Name}\" left");
                }
                catch (Exception ex)
                {
                    MMW.BroadcastMessage("log", $"[ERROR] player \"{player.Name}\" leave failed");
                }
            });
        }
Exemplo n.º 6
0
        public void ItemUse(NwWalkerGameObject go, WalkerPlayer player, bool sync)
        {
            MMW.Invoke(() =>
            {
                try
                {
                    if (!Players.Exists(p => (string)p.Properties["userID"] == player.UserID))
                    {
                        return;
                    }

                    var wo = Resources.Objects[go.ObjectHash];
                    if (!wo.Loaded)
                    {
                        wo.Load();
                    }

                    var g = GameObjectFactory.CreateItem(go, wo, player, "item", wo.Bones != null ? "Deferred Physical Skin" : "Deferred Physical");

                    g.Properties["user"]      = player;
                    g.Properties["userID"]    = player.UserID;
                    g.Properties["sessionID"] = player.SessionID;
                    g.Hash             = go.Hash;
                    g.Transform.Parent = Players.Find(p => (string)p.Properties["userID"] == player.UserID).Transform;
                    g.Transform.UpdatePhysicalTransform();

                    MMW.RegistGameObject(g);
                    if (sync)
                    {
                        SyncWorldObjects.Add(g);
                    }
                    else
                    {
                        WorldObjects.Add(g);
                    }
                }
                catch
                {
                    MMW.BroadcastMessage("log", $"[ERROR] failed to use item \"{go.Name}\"");
                }
            });
        }
Exemplo n.º 7
0
        public void RemoveGameObject(GameObject go)
        {
            MMW.Invoke(() =>
            {
                try
                {
                    SyncWorldObjects.Remove(go);
                    WorldObjects.Remove(go);
                    if (go != null)
                    {
                        MMW.DestroyGameObject(go);
                    }

                    MMW.BroadcastMessage("log", $"object \"{go.Name}\" removed");
                }
                catch
                {
                }
            });
        }
Exemplo n.º 8
0
        public bool Execute(Server server, int dataType, byte[] data, bool isTcp)
        {
            if (!isTcp)
            {
                return(false);
            }

            Buffer.Read(data, br =>
            {
                var res = br.ReadInt32();
                if (res >= 0)
                {
                    server.SessionID = res;
                }

                MMW.BroadcastMessage("login result", res >= 0);
                //server.EventLoginResultReceived(res >= 0);
            });

            return(true);
        }
Exemplo n.º 9
0
        public void PutGameObject(NwWalkerGameObject go, bool sync)
        {
            MMW.Invoke(() =>
            {
                try
                {
                    var wo = Resources.Objects[go.ObjectHash];
                    if (!wo.Loaded)
                    {
                        wo.Load();
                    }

                    var g  = GameObjectFactory.CreateGameObject(go, wo, wo.Name, wo.Bones != null ? "Deferred Physical Skin" : "Deferred Physical");
                    g.Hash = go.Hash;
                    g.Transform.Position = go.Position.FromVec3f();
                    g.Transform.Rotate   = go.Rotation.FromVec3f();
                    if (go.Scale != null)
                    {
                        g.Transform.Scale = go.Scale.FromVec3f();
                    }
                    g.Transform.UpdatePhysicalTransform();

                    MMW.RegistGameObject(g);
                    if (sync)
                    {
                        SyncWorldObjects.Add(g);
                    }
                    else
                    {
                        WorldObjects.Add(g);
                    }
                }
                catch
                {
                    MMW.BroadcastMessage("log", $"[ERROR] object \"{go.Name}\" entry failed");
                }
            });
        }
Exemplo n.º 10
0
        private void JoinPlayer(WalkerPlayer player)
        {
            MMW.Invoke(() =>
            {
                try
                {
                    var c = Resources.Characters[player.CharacterHash];
                    if (!c.Loaded)
                    {
                        c.Load();
                    }

                    var ch = GameObjectFactory.CreateCharacter(c, player.Name, c.Bones != null ? "Deferred Physical Skin" : "Deferred Physical");
                    ch.Properties["sessionID"] = player.SessionID;
                    ch.Properties["userID"]    = player.UserID;
                    ch.Properties["user"]      = player;
                    ch.AddComponent <CharacterInfo>(c, player);
                    ch.AddComponent <CharacterTransformResolver>(player);
                    ch.AddComponent <CharacterPopupResolver>();
                    ch.AddComponent <CharacterNameResolver>();
                    ch.Transform.Position = player.Position.FromVec3f();
                    ch.Transform.Rotate   = player.Rotation.FromVec3f();
                    ch.Transform.UpdatePhysicalTransform();

                    MMW.RegistGameObject(ch);
                    Players.Add(ch);
                    worldData.Players.Add(player);

                    MMW.BroadcastMessage("log", $"player \"{player.Name}\" joined");
                }
                catch (Exception ex)
                {
                    MMW.BroadcastMessage("log", $"[ERROR] player \"{player.Name}\" join failed");
                }
            });
        }
        protected override void OnLoad()
        {
            userData = MMW.GetAsset <UserData>();

            if (!userData.Achivements.Exists(ach => ach.Name == "Walk 1km"))
            {
                checkList.Add(() =>
                {
                    if (userData.TotalMoveDistance >= 1000.0f)
                    {
                        MMW.BroadcastMessage("get reward", Reward.CreatePublicReward(10, 30, "Walk 1km", "1Km歩いた"));
                        return(true);
                    }
                    return(false);
                });
            }
            if (!userData.Achivements.Exists(ach => ach.Name == "Walk 5km"))
            {
                checkList.Add(() =>
                {
                    if (userData.TotalMoveDistance >= 5000.0f)
                    {
                        MMW.BroadcastMessage("get reward", Reward.CreatePublicReward(30, 100, "Walk 5km", "5Km歩いた"));
                        return(true);
                    }
                    return(false);
                });
            }
            if (!userData.Achivements.Exists(ach => ach.Name == "Walk 10km"))
            {
                checkList.Add(() =>
                {
                    if (userData.TotalMoveDistance >= 10000.0f)
                    {
                        MMW.BroadcastMessage("get reward", Reward.CreatePublicReward(100, 300, "Walk 10km", "10Km歩いた"));
                        return(true);
                    }
                    return(false);
                });
            }
            if (!userData.Achivements.Exists(ach => ach.Name == "Walk 100km"))
            {
                checkList.Add(() =>
                {
                    if (userData.TotalMoveDistance >= 100000.0f)
                    {
                        MMW.BroadcastMessage("get reward", Reward.CreatePublicReward(300, 1000, "Walk 100km", "100Km歩いた"));
                        return(true);
                    }
                    return(false);
                });
            }
            if (!userData.Achivements.Exists(ach => ach.Name == "Walk 1000km"))
            {
                checkList.Add(() =>
                {
                    if (userData.TotalMoveDistance >= 1000000.0f)
                    {
                        MMW.BroadcastMessage("get reward", Reward.CreatePublicReward(1000, 4000, "Walk 1000km", "1000Km歩いた"));
                        return(true);
                    }
                    return(false);
                });
            }

            if (!userData.Achivements.Exists(ach => ach.Name == "Jump 100"))
            {
                checkList.Add(() =>
                {
                    if (userData.TotalJumpCount >= 100)
                    {
                        MMW.BroadcastMessage("get reward", Reward.CreatePublicReward(10, 30, "Jump 100", "100回ジャンプした"));
                        return(true);
                    }
                    return(false);
                });
            }
            if (!userData.Achivements.Exists(ach => ach.Name == "Jump 1000"))
            {
                checkList.Add(() =>
                {
                    if (userData.TotalJumpCount >= 1000)
                    {
                        MMW.BroadcastMessage("get reward", Reward.CreatePublicReward(100, 300, "Jump 1000", "1000回ジャンプした"));
                        return(true);
                    }
                    return(false);
                });
            }
            if (!userData.Achivements.Exists(ach => ach.Name == "Jump 10000"))
            {
                checkList.Add(() =>
                {
                    if (userData.TotalJumpCount >= 10000)
                    {
                        MMW.BroadcastMessage("get reward", Reward.CreatePublicReward(300, 1000, "Jump 10000", "10000回ジャンプした"));
                        return(true);
                    }
                    return(false);
                });
            }
            if (!userData.Achivements.Exists(ach => ach.Name == "Jump 100000"))
            {
                checkList.Add(() =>
                {
                    if (userData.TotalJumpCount >= 100000)
                    {
                        MMW.BroadcastMessage("get reward", Reward.CreatePublicReward(1000, 4000, "Jump 100000", "100000回ジャンプした"));
                        return(true);
                    }
                    return(false);
                });
            }

            if (!userData.Achivements.Exists(ach => ach.Name == "Playing 1 hour"))
            {
                checkList.Add(() =>
                {
                    if (userData.TotalPlayingTime >= 3600.0)
                    {
                        MMW.BroadcastMessage("get reward", Reward.CreatePublicReward(10, 30, "Playing 1 hour", "1時間プレイした"));
                        return(true);
                    }
                    return(false);
                });
            }
            if (!userData.Achivements.Exists(ach => ach.Name == "Playing 10 hour"))
            {
                checkList.Add(() =>
                {
                    if (userData.TotalPlayingTime >= 36000.0)
                    {
                        MMW.BroadcastMessage("get reward", Reward.CreatePublicReward(30, 100, "Playing 10 hour", "10時間プレイした"));
                        return(true);
                    }
                    return(false);
                });
            }
            if (!userData.Achivements.Exists(ach => ach.Name == "Playing 100 hour"))
            {
                checkList.Add(() =>
                {
                    if (userData.TotalPlayingTime >= 360000.0)
                    {
                        MMW.BroadcastMessage("get reward", Reward.CreatePublicReward(300, 1000, "Playing 100 hour", "100時間プレイした"));
                        return(true);
                    }
                    return(false);
                });
            }
            if (!userData.Achivements.Exists(ach => ach.Name == "Playing 1000 hour"))
            {
                checkList.Add(() =>
                {
                    if (userData.TotalPlayingTime >= 3600000.0)
                    {
                        MMW.BroadcastMessage("get reward", Reward.CreatePublicReward(1000, 4000, "Playing 1000 hour", "1000時間プレイした"));
                        return(true);
                    }
                    return(false);
                });
            }

            if (!userData.Achivements.Exists(ach => ach.Name == "Get 100 coin"))
            {
                checkList.Add(() =>
                {
                    if (userData.TotalGetCoin >= 100)
                    {
                        MMW.BroadcastMessage("get reward", Reward.CreatePublicReward(10, 30, "Get 100 coin", "合計100コインゲットした"));
                        return(true);
                    }
                    return(false);
                });
            }
            if (!userData.Achivements.Exists(ach => ach.Name == "Get 1000 coin"))
            {
                checkList.Add(() =>
                {
                    if (userData.TotalGetCoin >= 1000)
                    {
                        MMW.BroadcastMessage("get reward", Reward.CreatePublicReward(30, 100, "Get 1000 coin", "合計1000コインゲットした"));
                        return(true);
                    }
                    return(false);
                });
            }
            if (!userData.Achivements.Exists(ach => ach.Name == "Get 10000 coin"))
            {
                checkList.Add(() =>
                {
                    if (userData.TotalGetCoin >= 10000)
                    {
                        MMW.BroadcastMessage("get reward", Reward.CreatePublicReward(300, 1000, "Get 10000 coin", "合計10000コインゲットした"));
                        return(true);
                    }
                    return(false);
                });
            }
            if (!userData.Achivements.Exists(ach => ach.Name == "Get 100000 coin"))
            {
                checkList.Add(() =>
                {
                    if (userData.TotalGetCoin >= 100000)
                    {
                        MMW.BroadcastMessage("get reward", Reward.CreatePublicReward(1000, 4000, "Get 100000 coin", "合計100000コインゲットした"));
                        return(true);
                    }
                    return(false);
                });
            }
        }
Exemplo n.º 12
0
        public void Trigger(int tr, float length = float.MaxValue)
        {
            var player = MMW.FindGameObject(o => o.Tags.Contains("player"));

            MMW.BroadcastMessage("trigger", tr, player.Transform.WorldPosition, length);
        }
Exemplo n.º 13
0
        public void SwitchOff(int sw, float length = float.MaxValue)
        {
            var player = MMW.FindGameObject(o => o.Tags.Contains("player"));

            MMW.BroadcastMessage("switch off", sw, player.Transform.WorldPosition, length);
        }
Exemplo n.º 14
0
        public void Show()
        {
            controlDic.Clear();
            Shown = true;

            // shop
            {
                var list = new List <Control>();
                controlDic.Add("shop", list);

                var frame = new Frame(null, new Vector2(400, 200), new Vector2(440, MMW.Height - 200 - 100));
                list.Add(frame);

                var labelName = new Label(frame, "Name", ControlDrawer.fontSmallB, new Vector2(20, 10));
                list.Add(labelName);

                var labelPrice = new Label(labelName, "Price", ControlDrawer.fontSmallB, new Vector2(260, 0));
                list.Add(labelPrice);

                var labelBag = new Label(labelPrice, "Bag", ControlDrawer.fontSmallB, new Vector2(100, 0));
                list.Add(labelBag);

                var btnBuy = new Button(null, "Buy", new Vector2(MMW.Width - 160, MMW.Height - 124), new Vector2(60, 24), "click");
                btnBuy.Enabled  = false;
                btnBuy.Clicked += (s, e) =>
                {
                    var userData = MMW.GetAsset <UserData>();
                    btnBuy.Enabled = userData.Coin >= SelectRect.Focused.Price;
                    if (userData.Coin < SelectRect.Focused.Price)
                    {
                        return;
                    }

                    var o    = MMW.GetAsset <WorldResources>().Objects[SelectRect.Focused.Hash];
                    var info = new WalkerItemInfo()
                    {
                        Name     = o.Name,
                        Desc     = o.Desc,
                        Hash     = o.Hash,
                        Type     = o.ItemType,
                        Icon     = Util.FromBitmap(o.Icon),
                        MaxStack = o.MaxStack,
                        Consume  = o.Consume,
                        Price    = o.Price,
                        Sync     = o.Sync,
                    };

                    if (userData.AddItem(info, null))
                    {
                        userData.SubCoin(SelectRect.Focused.Price);
                        MMW.BroadcastMessage("log", $"Bought a \"{info.Name}\"");
                    }
                    else
                    {
                        MMW.BroadcastMessage("log", "Items are full");
                    }
                };
                list.Add(btnBuy);

                Control prev  = labelName;
                var     first = true;
                foreach (var o in MMW.GetAsset <WorldResources>().Objects)
                {
                    if (!o.Value.Purchasable)
                    {
                        continue;
                    }

                    var name = new Label(prev, o.Value.Name, new Vector2(0, 30));
                    if (first)
                    {
                        name.LocalLocation = new Vector2(0, 40);
                        first = false;
                    }
                    list.Add(name);

                    var price = new Label(name, o.Value.Price.ToString(), new Vector2(260, 0));
                    list.Add(price);

                    var bag = new Label(price, "0", new Vector2(100, 0));
                    list.Add(bag);

                    var rect = new SelectRect(name, new Vector2(-12.0f, 1.0f), new Vector2(420.0f, 24));
                    rect.Hash     = o.Key;
                    rect.Price    = o.Value.Price;
                    rect.Clicked += (s, e) =>
                    {
                        var userData = MMW.GetAsset <UserData>();
                        btnBuy.Enabled = userData.Coin >= rect.Price;

                        if (!o.Value.Loaded)
                        {
                            o.Value.Load();
                        }
                        drawObj.Load(o.Value.Mesh, o.Value.Materials);
                    };
                    list.Add(rect);

                    prev = name;
                }
            }

            // skill
            {
                var list = new List <Control>();
                controlDic.Add("skill", list);

                var labelSkill1 = new Label(null, "Skill Point", ControlDrawer.fontSmallB, new Vector2(400, 200));
                list.Add(labelSkill1);

                var labelSkill2 = new Label(null, userData.SkillPoint.ToString(), ControlDrawer.fontSmallB, new Vector2(520, 200));
                labelSkill2.Brush = Brushes.LightGreen;
                list.Add(labelSkill2);

                var frame = new Frame(null, new Vector2(400, 250), new Vector2(MMW.Width - 400 - 100, MMW.Height - 250 - 100));
                list.Add(frame);

                var labelName = new Label(frame, "Name", ControlDrawer.fontSmallB, new Vector2(20, 10));
                list.Add(labelName);
            }

            // players
            {
                var players = MMW.GetAsset <WorldData>().Players;
                var id      = MMW.GetAsset <UserData>().SessionID;
                var admin   = players.Find(p => p.SessionID == id).IsAdmin;

                var list = new List <Control>();

                var frame = new Frame(null, new Vector2(400, 200), new Vector2(MMW.Width - 400 - 100, MMW.Height - 200 - 100));
                list.Add(frame);

                var labelName = new Label(frame, "Name", ControlDrawer.fontSmallB, new Vector2(20, 10));
                list.Add(labelName);

                var labelRank = new Label(labelName, "Rank", ControlDrawer.fontSmallB, new Vector2(180, 0));
                list.Add(labelRank);

                var labelLiked = new Label(labelRank, "Liked", ControlDrawer.fontSmallB, new Vector2(80, 0));
                list.Add(labelLiked);

                var labelAchivements = new Label(labelLiked, "Achivements", ControlDrawer.fontSmallB, new Vector2(80, 0));
                list.Add(labelAchivements);

                var labelID = new Label(labelAchivements, "ID", ControlDrawer.fontSmallB, new Vector2(150, 0));
                list.Add(labelID);

                var labelBan = new Label(labelID, "Ban", ControlDrawer.fontSmallB, new Vector2(270, 0));
                if (admin)
                {
                    list.Add(labelBan);
                }


                Control prev  = labelName;
                bool    first = true;
                foreach (var p in players)
                {
                    var name = new Label(prev, p.Name, new Vector2(0, 30));
                    if (first)
                    {
                        name.LocalLocation = new Vector2(0, 40);
                        first = false;
                    }
                    list.Add(name);

                    var rank = new Label(name, p.Rank.ToString(), new Vector2(180, 0));
                    list.Add(rank);

                    var like = new Label(rank, p.LikedCount.ToString(), new Vector2(80, 0));
                    list.Add(like);

                    var achivement = new Label(like, p.Achivements.Count.ToString(), new Vector2(80, 0));
                    list.Add(achivement);

                    var userid = new Label(achivement, p.UserID, new Vector2(150, 0));
                    list.Add(userid);

                    if (admin && p.SessionID != id)
                    {
                        var ban = new Button(userid, "Ban", new Vector2(270, 0), new Vector2(48, 24), "click");
                        list.Add(ban);
                    }

                    prev = name;
                }

                controlDic.Add("players", list);
            }

            // graphics
            {
                var list = new List <Control>();
                controlDic.Add("graphics", list);
            }

            // leave
            {
                var list = new List <Control>();
                controlDic.Add("leave", list);

                var label = new Label(null, "Are you sure you want to leave world?", new Vector2(400, 200));
                list.Add(label);

                var btn = new Button(label, "OK", new Vector2(0, 40), "click");
                btn.Clicked += (s, e) =>
                {
                    GameObject.SendMessage("close leave window");
                    var ws = MMW.FindGameComponent <WalkerScript>();
                    MMW.DestroyGameObject(ws.GameObject);

                    var title = new GameObject("Title", Matrix4.Identity, "title");
                    MMW.RegistGameObject(title);
                    title.AddComponent <BackgroundScript>();
                    title.AddComponent <TitleScript>();
                    MMW.Window.CursorVisible = true;
                };
                list.Add(btn);
            }
        }
Exemplo n.º 15
0
        protected override void Update(double deltaTime)
        {
            if (Input.IsButtonPressed(OpenTK.Input.MouseButton.Right))
            {
                var idx  = userData.ItemSelectIndex;
                var item = userData.HotbarItems[idx];
                if (item == null)
                {
                    return;
                }

                if (!resources.Objects.ContainsKey(item.Info.Hash))
                {
                    MMW.BroadcastMessage("log", "item unavailable in this world");
                }

                var scripts = new List <NwWalkerGameObject.NwScriptInfo>();
                var objs    = MMW.GetAsset <WorldResources>().Objects;

                foreach (var s in objs[item.Info.Hash].nwObject.Scripts)
                {
                    scripts.Add(new NwWalkerGameObject.NwScriptInfo()
                    {
                        Hash   = s.Hash,
                        Status = null,
                    });
                }

                var obj = new NwWalkerGameObject()
                {
                    CreateDate  = DateTime.Now.ToString(),
                    CreatorName = userData.Name,
                    Hash        = Util.CreateHash(12),
                    Name        = item.Info.Name,
                    ObjectHash  = item.Info.Hash,
                    Position    = data.position.ToVec3f(),
                    Rotation    = data.rotate.ToVec3f(),
                    Scale       = new Vector3f(1.0f, 1.0f, 1.0f),
                    SessionID   = userData.SessionID,
                    UserID      = userData.UserID,
                    Scripts     = scripts.ToArray(),
                };

                if (focusedObj != null && item.Info.Type == "Put")
                {
                    if (item.Info.Consume)
                    {
                        item.Number--;
                        if (item.Number <= 0)
                        {
                            userData.HotbarItems[idx] = null;
                        }
                    }
                    if (item.Info.Sync)
                    {
                        server.SendTcp(DataType.RequestObjectPut, obj);
                        MMW.BroadcastMessage("log", "sync put item");
                    }
                    else if (item.Number > 0)
                    {
                        MMW.FindGameComponent <WalkerScript>().PutGameObject(obj, false);
                        MMW.BroadcastMessage("log", "put item");
                    }
                }
                else if (item.Info.Type == "Use")
                {
                    if (item.Info.Consume)
                    {
                        item.Number--;
                        if (item.Number <= 0)
                        {
                            userData.HotbarItems[idx] = null;
                        }
                    }
                    if (item.Info.Sync)
                    {
                        server.SendTcp(DataType.RequestItemUsed, obj);
                        MMW.BroadcastMessage("log", "sync use item");
                    }
                    else if (item.Number > 0)
                    {
                        MMW.FindGameComponent <WalkerScript>().ItemUse(obj, GameObject.GetComponent <CharacterInfo>().Player, false);
                        MMW.BroadcastMessage("log", "use item");
                    }
                }
            }
            else if (Input.IsButtonDown(OpenTK.Input.MouseButton.Right))
            {
                var idx  = userData.ItemSelectIndex;
                var item = userData.HotbarItems[idx];
                if (item == null)
                {
                    return;
                }

                if (!resources.Objects.ContainsKey(item.Info.Hash))
                {
                    MMW.BroadcastMessage("log", "item unavailable in this world");
                }

                if (item.Info.Type == "Throw")
                {
                }
            }
            else if (Input.IsKeyPressed(OpenTK.Input.Key.Q))
            {
                var idx  = userData.ItemSelectIndex;
                var item = userData.HotbarItems[idx];
                if (item == null)
                {
                    return;
                }

                userData.HotbarItems[idx] = null;
            }
        }
Exemplo n.º 16
0
        protected override void OnLoad()
        {
            Layer = LayerUI + 2;

            userData = MMW.GetAsset <UserData>();

            var label = new Label(
                null,
                "MENU",
                new Font("Yu Gothic UI", 32.0f),
                new Vector2((MMW.Width - Drawer.MeasureString("MENU", new Font("Yu Gothic UI", 32.0f)).X) / 2.0f, 100.0f));

            controls.Add(label);

            var btnShop = new Button(null, "Shop", new Vector2(200, 200), "click");

            btnShop.Clicked += (s, e) =>
            {
                type = "shop";
                MMW.BroadcastMessage("show coin resolver");
            };
            controls.Add(btnShop);

            var btnSkill = new Button(btnShop, "Skill", new Vector2(0, 50), "click");

            btnSkill.Clicked += (s, e) =>
            {
                type = "skill";
                MMW.BroadcastMessage("close coin resolver");
            };
            controls.Add(btnSkill);

            var btnPlayers = new Button(btnSkill, "Players", new Vector2(0, 50), "click");

            btnPlayers.Clicked += (s, e) =>
            {
                type = "players";
                MMW.BroadcastMessage("close coin resolver");
            };
            controls.Add(btnPlayers);

            var btnGraphics = new Button(btnPlayers, "Graphics", new Vector2(0, 50), "click");

            btnGraphics.Clicked += (s, e) =>
            {
                type = "graphics";
                MMW.BroadcastMessage("close coin resolver");
            };
            controls.Add(btnGraphics);

            var btnExit = new Button(btnGraphics, "Leave", new Vector2(0, 50), "click");

            btnExit.Clicked += (s, e) =>
            {
                type = "leave";
                MMW.BroadcastMessage("close coin resolver");
            };
            controls.Add(btnExit);

            drawObj = new SimpleDrawableObject();
        }
Exemplo n.º 17
0
 public void BroadcastMessage(string message, params object[] args)
 {
     MMW.BroadcastMessage(message, args);
 }
Exemplo n.º 18
0
 public void Log(object log)
 {
     MMW.BroadcastMessage("log", log.ToString());
 }
Exemplo n.º 19
0
        protected override void Update(double deltaTime)
        {
            userData.TotalPlayingTime += deltaTime;

            if (AllowFunctionKey && Input.IsKeyPressed(Key.F2))
            {
                MMW.MainCamera.TargetTexture.ColorDst0.Save(GameData.AppDir + "pic_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".png", System.Drawing.Imaging.ImageFormat.Png);
            }

            if (AllowFunctionKey && Input.IsKeyPressed(Key.F3))
            {
                MMW.Window.CursorVisible = !MMW.Window.CursorVisible;
            }

            if (AllowFunctionKey && Input.IsAnyKeyPressed(Key.F4))
            {
                hudShown = !hudShown;
                if (hudShown)
                {
                    MMW.BroadcastMessage("hud show");
                }
                else
                {
                    MMW.BroadcastMessage("hud hide");
                }
            }

            if (AllowFunctionKey && Input.IsKeyPressed(Key.F5))
            {
                fps = !fps;
                if (fps)
                {
                    MMW.BroadcastMessage("camera change", "first person");
                }
                else
                {
                    MMW.BroadcastMessage("camera change", "third person");
                }
            }

            if (AllowFunctionKey && Input.IsKeyPressed(Key.F6))
            {
                MMW.BroadcastMessage("change chara display");
            }

            if (!menuShown && AllowFunctionKey && Input.IsKeyPressed(Key.E))
            {
                inventoryShown = !inventoryShown;
                if (inventoryShown)
                {
                    MMW.BroadcastMessage("show dialog");
                    MMW.BroadcastMessage("show inventory");
                }
                else
                {
                    MMW.BroadcastMessage("close dialog");
                    MMW.BroadcastMessage("close inventory");
                }
            }

            if (!inventoryShown && AllowFunctionKey && Input.IsKeyPressed(Key.T))
            {
                menuShown = !menuShown;
                if (menuShown)
                {
                    MMW.BroadcastMessage("show dialog");
                    MMW.BroadcastMessage("show menu");
                }
                else
                {
                    MMW.BroadcastMessage("close dialog");
                    MMW.BroadcastMessage("close menu");
                }
            }

            checkTime -= deltaTime;
            if (checkTime < 0)
            {
                checkTime += 10.0;
                userData.Save();
                server.SendTcp(Walker.DataType.RequestWorldStatus, new byte[0]);
            }
        }