Esempio n. 1
0
        private void Update()
        {
            if (moveInputPending > 0.0f)
            {
                moveInputPending -= Time.deltaTime;
            }
            else
            {
                twin move = Pin.GetTwinDown();
                if (move.taxicabLength == 1)
                {
                    moveInputPending = 1.0f;
                    link.Post <OK>(WorldMove.OPCODE, new WorldMove {
                        dir = move
                    },
                                   ok =>
                    {
                        //moveInputPending = 0.0f;
                    },
                                   failReason =>
                    {
                        moveInputPending = 0.0f;
                    });
                }
            }

            if (currentSession == null || currentZone == null || myEntity == null)
            {
                //Dj.Tempf("{0}--{1}--{2}", currentSession, currentZone, myEntity);
                tmp_display.text = "connecting...";
            }
            else
            {
                tmp_display.text = string.Format("Your session:@{0}\nIn zone '{1}'@{2}\nYour position within the world: {3}\n# of other ents here: {4}",
                                                 currentSession.address, currentZone.ZoneName, currentZone.WorldPos, myEntity.Position, visibleEntities.Count);
            }
        }
Esempio n. 2
0
        private void Start()
        {
            link     = GetComponent <ClientsideLink>();
            sessions = new ClientsideSessions(link);
            link.AttemptConnection(success =>
            {
                if (success)
                {
                    sessions.DoLogin("droqen");
                }
                else
                {
                    Dj.Warnf("Login failed. TODO: Implement retry");
                }
            });
            sessions.AddStoryfan(Session.OPCODE, new LambdaStoryfan <Session>(session =>
            {
                if (currentSession == null || currentSession.Username != session.Username)
                {
                    currentSession = session;
                    link.Post <OK>(RequestStories.OPCODE, new RequestStories {
                        message = "Hello from " + currentSession.Username,
                    },
                                   reply =>
                    {
                    },
                                   failStatus =>
                    {
                        Dj.Tempf("RequestStories rejected with status {0}. Recommended to either request again, or disconnect.", failStatus);
                    });
                }

                Dj.Tempf("My session says my name is '{0}'", currentSession.Username);
            }));

            sessions.AddStoryfan(TowerZone.OPCODE, new LambdaStoryfan <TowerZone>(zone =>
            {
                currentZone = zone;

                visibleEntities.Clear();
            }));

            sessions.AddStoryfan(TowerEntity.OPCODE, new LambdaStoryfan <TowerEntity>(ent =>
            {
                bool its_me = false;
                try
                {
                    if (currentSession.EntityId == ent.EntityId)
                    {
                        myEntity = ent;
                        its_me   = true;
                    }
                }
                catch { }

                if (!its_me)
                {
                    if (ent.WorldPos == currentZone.WorldPos)
                    {
                        visibleEntities.Add(ent);
                    }
                    else
                    {
                        visibleEntities.Remove(ent);
                    }
                }
            }));

            sessions.PushStorydecoder(new TowerStoryDecoder());
        }