Beispiel #1
0
        public void OnRemoveBikeCmd(RemoveBikeMsg msg)
        {
            logger.Info($"OnRemoveBikeCmd({msg.bikeId}) Now: {FrameApianTime} Ts: {msg.TimeStamp}");
            IBike ib = CoreData.GetBaseBike(msg.bikeId);

            _RemoveBike(ib, true);
        }
Beispiel #2
0
        public void OnPlaceClaimCmd(PlaceClaimMsg msg)
        {
            // Apian has said this message is authoritative
            BaseBike b = CoreData.GetBaseBike(msg.bikeId);

            if (CoreData.Ground.IndicesAreOnMap(msg.xIdx, msg.zIdx))
            {
                if (b == null)
                {
                    logger.Warn($"OnPlaceClaimCmd() Bike:{msg.bikeId} not found!"); // can happen if RemoveCmd and ClaimObs interleave
                    return;
                }

                b.UpdatePosFromCommand(msg.TimeStamp, FrameApianTime, BeamPlace.PlacePos(msg.xIdx, msg.zIdx), msg.exitHead);

                // Claim it
                BeamPlace p = CoreData.ClaimPlace(b, msg.xIdx, msg.zIdx, msg.TimeStamp + BeamPlace.kLifeTimeMs);
                if (p != null)
                {
                    ApplyScoreUpdate(msg.scoreUpdates);
                    logger.Verbose($"OnPlaceClaimCmd() Bike: {b.bikeId} claimed {BeamPlace.PlacePos( msg.xIdx, msg.zIdx).ToString()} at {msg.TimeStamp}");
                    //logger.Verbose($"                  BikePos: {b.position.ToString()}, FrameApianTime: {FrameApianTime} ");
                    //logger.Verbose($"   at Timestamp:  BikePos: {b.PosAtTime(msg.TimeStamp, FrameApianTime).ToString()}, Time: {msg.TimeStamp} ");
                    PlaceClaimedEvt?.Invoke(this, p);
                }
                else
                {
                    logger.Warn($"OnPlaceClaimCmd()) failed. Place already claimed.");
                }
            }
        }
Beispiel #3
0
        public void OnBikeCommandCmd(BikeCommandMsg msg)
        {
            BaseBike bb = CoreData.GetBaseBike(msg.bikeId);

            logger.Verbose($"OnBikeCommandCmd({msg.cmd}) Now: {FrameApianTime} Ts: {msg.TimeStamp} Bike:{msg.bikeId}");
            bb.ApplyCommand(msg.cmd, new Vector2(msg.nextPtX, msg.nextPtZ), msg.TimeStamp);
        }
Beispiel #4
0
        public void OnBikeTurnCmd(BikeTurnMsg msg)
        {
            BaseBike bb = CoreData.GetBaseBike(msg.bikeId);

            logger.Verbose($"OnBikeTurnCmd({msg.dir}) Now: {FrameApianTime} Ts: {msg.TimeStamp} Bike:{msg.bikeId}");
            if (bb == null)
            {
                logger.Warn($"OnBikeTurnCmd() Bike:{msg.bikeId} not found!");
            }
            bb?.ApplyTurn(msg.dir, msg.entryHead, new Vector2(msg.nextPtX, msg.nextPtZ), msg.TimeStamp, msg.bikeState);
        }
Beispiel #5
0
 protected void ApplyScoreUpdate(Dictionary <string, int> update)
 {
     foreach (string id in update.Keys)
     {
         IBike bike = CoreData.GetBaseBike(id);
         bike?.AddScore(update[id]);
         if (bike.score <= 0)
         {
             logger.Info($"ApplyScoreUpdate(). Bike: {bike.bikeId} has no score anymore!");
             apian.SendRemoveBikeObs(FrameApianTime, bike.bikeId);
         }
     }
 }
Beispiel #6
0
        public bool _AddBike(IBike ib)
        {
            logger.Verbose($"_AddBike(): {ib.bikeId} at ({ib.basePosition.x}, {ib.basePosition.y})");

            if (CoreData.GetBaseBike(ib.bikeId) != null)
            {
                return(false);
            }

            CoreData.Bikes[ib.bikeId] = ib;

            NewBikeEvt?.Invoke(this, ib);

            return(true);
        }
Beispiel #7
0
        public void OnPlaceHitCmd(PlaceHitMsg msg)
        {
            // Apian has already checked the the place is claimed and the bike exists
            Vector2   pos         = BeamPlace.PlacePos(msg.xIdx, msg.zIdx);
            BeamPlace p           = CoreData.GetPlace(pos);
            BaseBike  hittingBike = CoreData.GetBaseBike(msg.bikeId);

            if (p != null && hittingBike != null)
            {
                hittingBike.UpdatePosFromCommand(msg.TimeStamp, FrameApianTime, p.GetPos(), msg.exitHead);
                logger.Info($"OnPlaceHitCmd{p?.GetPos().ToString()} Now: {FrameApianTime} Ts: {msg.TimeStamp} Bike: {hittingBike?.bikeId} Pos: {p?.GetPos().ToString()}");
                ApplyScoreUpdate(msg.scoreUpdates);
                PlaceHitEvt?.Invoke(this, new PlaceHitArgs(p, hittingBike));
            }
            else
            {
                logger.Info($"OnPlaceHitCmd{p?.GetPos().ToString()} Now: {FrameApianTime} Ts: {msg.TimeStamp} Bike: {hittingBike?.bikeId} Pos: {p?.GetPos().ToString()}");
            }
        }