Esempio n. 1
0
        public override void Ignite()
        {
            EnumGameMode mode = World?.PlayerByUid(PlayerUID)?.WorldData?.CurrentGameMode ?? EnumGameMode.Survival;

            if (mode == EnumGameMode.Creative || mode == EnumGameMode.Spectator)
            {
                return;
            }

            base.Ignite();
        }
Esempio n. 2
0
        public override bool ShouldReceiveDamage(DamageSource damageSource, float damage)
        {
            EnumGameMode mode = World?.PlayerByUid(PlayerUID)?.WorldData?.CurrentGameMode ?? EnumGameMode.Survival;

            if ((mode == EnumGameMode.Creative || mode == EnumGameMode.Spectator) && damageSource?.Type != EnumDamageType.Heal)
            {
                return(false);
            }

            return(base.ShouldReceiveDamage(damageSource, damage));
        }
        public void Check()
        {
            if (entity is EntityPlayer)
            {
                EntityPlayer plr  = (EntityPlayer)entity;
                EnumGameMode mode = entity.World.PlayerByUid(plr.PlayerUID).WorldData.CurrentGameMode;
                if (mode == EnumGameMode.Creative || mode == EnumGameMode.Spectator)
                {
                    return;
                }
            }

            BlockPos pos = new BlockPos(
                (int)(entity.ServerPos.X + entity.LocalEyePos.X),
                (int)(entity.ServerPos.Y + entity.LocalEyePos.Y),
                (int)(entity.ServerPos.Z + entity.LocalEyePos.Z)
                );

            Block block = entity.World.BlockAccessor.GetBlock(pos);

            Cuboidf[] collisionboxes = block.GetCollisionBoxes(entity.World.BlockAccessor, pos);

            Cuboidf box = new Cuboidf();

            if (collisionboxes == null)
            {
                return;
            }

            for (int i = 0; i < collisionboxes.Length; i++)
            {
                box.Set(collisionboxes[i]);
                box.OmniGrowBy(-padding);
                tmp.Set(pos.X + box.X1, pos.Y + box.Y1, pos.Z + box.Z1, pos.X + box.X2, pos.Y + box.Y2, pos.Z + box.Z2);
                box.OmniGrowBy(padding);

                if (tmp.Contains(entity.ServerPos.X + entity.LocalEyePos.X, entity.ServerPos.Y + entity.LocalEyePos.Y, entity.ServerPos.Z + entity.LocalEyePos.Z))
                {
                    Cuboidd EntitySuffocationBox = entity.CollisionBox.ToDouble();

                    if (tmp.Intersects(EntitySuffocationBox))
                    {
                        DamageSource dmgsrc = new DamageSource()
                        {
                            Source = EnumDamageSource.Block, SourceBlock = block, Type = EnumDamageType.Suffocation
                        };
                        entity.ReceiveDamage(dmgsrc, 1f);
                        break;
                    }
                }
            }
        }
Esempio n. 4
0
        public override void OnGameTick(float deltaTime)
        {
            if (entity is EntityPlayer)
            {
                EntityPlayer plr = (EntityPlayer)entity;
                if (entity.World.PlayerByUid(plr.PlayerUID).WorldData.CurrentGameMode == EnumGameMode.Creative)
                {
                    return;
                }

                EnumGameMode mode = entity.World.PlayerByUid(plr.PlayerUID).WorldData.CurrentGameMode;
                if (mode == EnumGameMode.Creative || mode == EnumGameMode.Spectator)
                {
                    return;
                }

                if (plr.Controls.TriesToMove || plr.Controls.Jump || plr.Controls.LeftMouseDown || plr.Controls.RightMouseDown)
                {
                    lastMoveMs = entity.World.ElapsedMilliseconds;
                }
            }


            sprintCounter += entityAgent != null && entityAgent.Controls.Sprint ? 1 : 0;
            hungerCounter += deltaTime;

            // Once every 10s
            if (hungerCounter > 10)
            {
                bool  isStandingStill   = (entity.World.ElapsedMilliseconds - lastMoveMs) > 3000;
                float satLossMultiplier = isStandingStill ? 1 / 3f : 1f;
                //if (!entityAgent.LeftHandItemSlot.Empty) satLossMultiplier *= 1.25f; - Now set in InventoryPlayerHotbar

                satLossMultiplier *= 1.2f * (8 + sprintCounter / 15f) / 10f;

                satLossMultiplier *= entity.Stats.GetBlended("hungerrate");

                ReduceSaturation(satLossMultiplier);

                hungerCounter = 0;
                sprintCounter = 0;
            }
        }
        public override void OnGameTick(float deltaTime)
        {
            breatheCounter += deltaTime;
            if (breatheCounter < 1 || !entity.Alive)
            {
                return;
            }


            if (entity is EntityPlayer)
            {
                EntityPlayer plr  = (EntityPlayer)entity;
                EnumGameMode mode = entity.World.PlayerByUid(plr.PlayerUID).WorldData.CurrentGameMode;
                if (mode == EnumGameMode.Creative || mode == EnumGameMode.Spectator)
                {
                    return;
                }
            }

            EnumSuffocationType danger = checkSuffocation();

            if (danger == EnumSuffocationType.None)
            {
                this.Oxygen = Math.Min(this.MaxOxygen, Oxygen + breatheCounter);
            }
            else
            {
                float prevOxy = Oxygen;
                Oxygen -= depletionRate(breatheCounter);
                triggerSoundEffect(prevOxy, Oxygen, danger);

                if (Oxygen < 0)
                {
                    DamageSource damage = new DamageSource();
                    damage.source = EnumDamageSource.Drown;
                    damage.type   = EnumDamageType.Asphyxiation;
                    entity.Die(EnumDespawnReason.Death, damage);
                }
            }
            breatheCounter = 0;
        }
Esempio n. 6
0
 public static bool IsGuest(this EnumGameMode gamemode) => gamemode == EnumGameMode.Guest;
Esempio n. 7
0
 public static bool IsSpectator(this EnumGameMode gamemode) => gamemode == EnumGameMode.Spectator;
Esempio n. 8
0
 public static bool IsCreative(this EnumGameMode gamemode) => gamemode == EnumGameMode.Creative;
Esempio n. 9
0
 public static bool IsSurvival(this EnumGameMode gamemode) => gamemode == EnumGameMode.Survival;
        public async Task ProcessGameOptionChosenAsync(EnumGameMode optionChosen, bool doShow)
        {
            if (doShow)
            {
                _model !.ModeChoose1 !.SelectSpecificItem((int)optionChosen);
                if (_gameContainer.Test !.NoAnimations == false)
                {
                    await _gameContainer.Delay !.DelaySeconds(.5);
                }
                _gameContainer.SaveRoot !.GameMode = optionChosen;
            }
            else if (optionChosen != _gameContainer.SaveRoot !.GameMode)
            {
                throw new BasicBlankException("Had to show");
            }
            if (_delegates.CloseModeAsync == null)
            {
                throw new BasicBlankException("Nobody is closing the game mode.  Rethink");
            }
            await _delegates.CloseModeAsync.Invoke();

            if (_gameContainer.SaveRoot.GameStatus != EnumStatusList.ChooseGameType)
            {
                if (_gameContainer.SaveRoot.GameStatus == EnumStatusList.Bidding)
                {
                    _model.TrickArea1 !.Visible = false; //just in case.
                    await LoadBidAsync();

                    await _bidProcesses.BeginBiddingAsync();

                    return;
                }
                if (_gameContainer.SaveRoot.GameStatus == EnumStatusList.CallShape)
                {
                    _model !.ShapeChoose1 !.Visible = true;//just in case.
                    await _shapeProcesses.FirstCallShapeAsync();

                    return;
                }
                if (_gameContainer.SaveRoot.ClearTricks)
                {
                    _gameContainer.SaveRoot.ClearTricks = false;
                    await _bidProcesses.EndBidAsync();

                    return; //try this way.
                }
                if (_gameContainer.SaveRoot.ShapeChosen != EnumShapes.None)
                {
                    _model !.ShapeChoose1 !.ChoosePiece(_gameContainer.SaveRoot.ShapeChosen); //hopefully this simple.
                }
                _gameContainer.SingleInfo = _gameContainer.PlayerList !.GetWhoPlayer();
                if (_gameContainer.ShowTurn == null)
                {
                    throw new BasicBlankException("Nobody is showing turn.  Rethink");
                }
                _gameContainer.ShowTurn();
                await _gameContainer.ContinueTurnAsync !.Invoke();
                return;
            }
            if (optionChosen == EnumGameMode.ToBid)
            {
                _gameContainer.SingleInfo          = _gameContainer.PlayerList !.GetWhoPlayer();
                _gameContainer.SaveRoot.GameStatus = EnumStatusList.Bidding;
                await LoadBidAsync();

                await _bidProcesses.PopulateBidAmountsAsync();

                return;
            }
            await _bidProcesses.EndBidAsync();
        }
Esempio n. 11
0
        public override void OnGameTick(float deltaTime)
        {
            if (entity is EntityPlayer)
            {
                EntityPlayer plr  = (EntityPlayer)entity;
                EnumGameMode mode = entity.World.PlayerByUid(plr.PlayerUID).WorldData.CurrentGameMode;
                if (mode == EnumGameMode.Creative || mode == EnumGameMode.Spectator)
                {
                    return;
                }

                if (plr.Controls.TriesToMove || plr.Controls.Jump)
                {
                    lastMoveMs = entity.World.ElapsedMilliseconds;
                }
            }


            sprintCounter += entityAgent != null && entityAgent.Controls.Sprint ? 1 : 0;

            //deltaTime *= 10;

            hungerCounter += deltaTime;


            // Once every 10s
            if (hungerCounter > 10)
            {
                bool  isStandingStill = (entity.World.ElapsedMilliseconds - lastMoveMs) > 3000;
                float standStillFac   = isStandingStill ? 1 / 3f : 1f;

                bool isondelay = false;

                if (SaturationLossDelayFruit > 0)
                {
                    SaturationLossDelayFruit -= 10 * standStillFac;
                    isondelay = true;
                }
                else
                {
                    FruitLevel = Math.Max(0, FruitLevel - Math.Max(1, 0.001f * FruitLevel * standStillFac));
                }

                if (SaturationLossDelayVegetable > 0)
                {
                    SaturationLossDelayVegetable -= 10 * standStillFac;
                    isondelay = true;
                }
                else
                {
                    VegetableLevel = Math.Max(0, VegetableLevel - Math.Max(1, 0.001f * VegetableLevel * standStillFac));
                }

                if (SaturationLossDelayProtein > 0)
                {
                    SaturationLossDelayProtein -= 10 * standStillFac;
                    isondelay = true;
                }
                else
                {
                    ProteinLevel = Math.Max(0, ProteinLevel - Math.Max(1, 0.001f * ProteinLevel) * standStillFac);
                }

                if (SaturationLossDelayGrain > 0)
                {
                    SaturationLossDelayGrain -= 10 * standStillFac;
                    isondelay = true;
                }
                {
                    GrainLevel = Math.Max(0, GrainLevel - Math.Max(1, 0.001f * GrainLevel) * standStillFac);
                }

                if (SaturationLossDelayDairy > 0)
                {
                    SaturationLossDelayDairy -= 10 * standStillFac;
                    isondelay = true;
                }
                else
                {
                    DairyLevel = Math.Max(0, DairyLevel - Math.Max(1, 0.001f * DairyLevel) * standStillFac);
                }

                UpdateNutrientHealthBoost();

                if (isondelay)
                {
                    hungerCounter -= 10;
                    return;
                }

                float prevSaturation = Saturation;
                float satLoss        = (8 + sprintCounter / 15f) * standStillFac;

                if (prevSaturation > 0)
                {
                    Saturation    = Math.Max(0, prevSaturation - satLoss);
                    sprintCounter = 0;
                }

                hungerCounter -= 10;
            }
        }