Inheritance: AbstractPlayer
コード例 #1
0
        protected Matrix4 CalculateWorldMatrix(ItemViewbob viewbob)
        {
            SimpleCamera camera = OwnerPlayer.GetCamera();

            if (OwnerPlayer.IsRenderingThirdperson)
            {
                return(Matrix4.CreateScale(ThirdpersonScale)
                       * Matrix4.CreateTranslation(0, 1.5f, -0.25f)
                       * Matrix4.CreateRotationX(MathHelper.ToRadians(ModelRotation.X))
                       * Matrix4.CreateRotationY(MathHelper.ToRadians(ModelRotation.Y))
                       * Matrix4.CreateRotationZ(MathHelper.ToRadians(viewbob.CurrentTilt + ModelRotation.Z))
                       * Matrix4.CreateTranslation(ModelOffset + viewbob.CurrentViewBob + new Vector3(-1.35f, 0, -viewbob.CurrentKickback + -2))
                       * Matrix4.CreateRotationX(MathHelper.ToRadians(camera.Pitch))
                       * Matrix4.CreateRotationY(MathHelper.ToRadians(-camera.Yaw) + MathHelper.Pi)
                       * Matrix4.CreateTranslation(OwnerPlayer.Transform.Position
                                                   + new Vector3(0, OwnerPlayer.Size.Y / 2f - 1.5f, 0)));
            }
            else
            {
                return(Matrix4.CreateRotationX(MathHelper.ToRadians(ModelRotation.X + viewbob.CurrentSway.X))
                       * Matrix4.CreateRotationY(MathHelper.ToRadians(ModelRotation.Y + viewbob.CurrentSway.Y))
                       * Matrix4.CreateRotationZ(MathHelper.ToRadians(viewbob.CurrentTilt
                                                                      + ModelRotation.Z + viewbob.CurrentSway.Y * 0.5f))
                       * Matrix4.CreateTranslation(ModelOffset + viewbob.CurrentViewBob + new Vector3(0, 0, -viewbob.CurrentKickback))
                       * Matrix4.CreateRotationX(MathHelper.ToRadians(camera.Pitch))
                       * Matrix4.CreateRotationY(MathHelper.ToRadians(-camera.Yaw) + MathHelper.Pi)
                       * Matrix4.CreateTranslation(camera.OffsetPosition));
            }
        }
コード例 #2
0
        public void AddUnit(BaseUnit unit)
        {
            if (unit.Group != null && unit.Group != this)
            {
                unit.Group.RemoveUnit(unit);
            }

            if (!_units.Exists(u => u.Id == unit.Id))
            {
                SetDirty(GameConstants.DirtyStatus.UnitChanged);
                _units.Add(unit);
                unit.SetDirty(GameConstants.DirtyStatus.UnitChanged);
                GameManager.Instance.Log.LogDebug(
                    string.Format("Group {0} adds unit {1}. Count={2}",
                                  Id, unit.ToString(), _units.Count));
                if (_mainUnit == null)
                {
                    _mainUnit = unit;
                }
                if (OwnerPlayer != null)
                {
                    OwnerPlayer.RemoveGroup(this);
                    OwnerPlayer.AddGroup(this);
                }
            }
            unit.Group = this;
        }
コード例 #3
0
 void Start()
 {
     // Set the initial health of the player.
     playerScript = player.GetComponent<OwnerPlayer>();
     healthSlider.maxValue = playerScript.MaxHealth;
     healthSlider.value = healthSlider.maxValue;
     damaged = false;
 }
コード例 #4
0
ファイル: PlayerHealth.cs プロジェクト: hne3/GameProject
 void Start()
 {
     // Set the initial health of the player.
     playerScript          = player.GetComponent <OwnerPlayer>();
     healthSlider.maxValue = playerScript.MaxHealth;
     healthSlider.value    = healthSlider.maxValue;
     damaged = false;
 }
コード例 #5
0
        /// <summary>
        /// Returns true if the ability will be applied to the unit
        /// </summary>
        internal bool DoesAffect(LiveUnit u)
        {
            if (u.ContainsBuffType(BuffType.IsImmortal))
            {
                return(false);
            }
            OwnerPlayer targets = validTargetMask & u.OwnerPlayer;

            return(targets == u.OwnerPlayer);
        }
コード例 #6
0
    public void OnClick_Pon()
    {
        if (isMenuEnable(EActionType.Pon))
        {
            //Debug.Log("+ OnClick_Pon()");

            PlayerAction.Response = EResponse.Pon;

            NotifyHide();
            OwnerPlayer.OnPlayerInputFinished();
        }
    }
コード例 #7
0
        public LiveUnit(int maxHealth, OwnerPlayer owner)
        {
            this.maxHealth    = maxHealth;
            this.ownerPlayer  = owner;
            currentHealth     = maxHealth;
            currentHealsTaken = baseHealsTaken;
            this.Abilities    = new List <Ability>();
            this.buffs        = new Dictionary <string, Buff>();

            //The unit has moved and has attacked by default
            this.hasMoved    = true;
            this.hasAttacked = true;
        }
コード例 #8
0
ファイル: Mine.cs プロジェクト: JHaugland/WetAffairs
        public override void Tick(double timer)
        {
            base.Tick(timer);
            if (this.IsMarkedForDeletion || this.Position == null || ReadyInSec > 0 || GameManager.Instance.Game == null)
            {
                return;
            }
            var timePassedSinceLastTickSec = GameManager.Instance.Game.GameCurrentTime.Subtract(_timeLastTick).TotalSeconds;

            if (timePassedSinceLastTickSec < 10)
            {
                return;
            }
            _timeLastTick = DateTime.FromBinary(GameManager.Instance.Game.GameCurrentTime.ToBinary());
            var enemyUnits = OwnerPlayer.GetEnemyUnitsInAreaByUnitType(GameConstants.UnitType.SurfaceShip,
                                                                       this.Position.Coordinate,
                                                                       GameConstants.MAX_MINE_DETECTION_RANGE_M);

            foreach (var unit in enemyUnits)
            {
                if (unit.SupportsRole(GameConstants.Role.MineCountermeasures))
                {
                    var msgToMineOwner = new GameStateInfo(GameConstants.GameStateInfoType.MineDestroyedByEnemy, this.Id);
                    OwnerPlayer.Send(msgToMineOwner);

                    var msgToMineDestroyer = new GameStateInfo(GameConstants.GameStateInfoType.MineDestroyedByUs, unit.Id);
                    unit.OwnerPlayer.Send(msgToMineDestroyer);

                    //var msg = OwnerPlayer.CreateNewMessage(
                    //    string.Format("A {0} has been destroyed by enemy mine countermeasures.", ToShortString()));
                    //msg.Position = this.Position.Clone();

                    //var msg2 = unit.OwnerPlayer.CreateNewMessage(
                    //    string.Format("An enemy {0} has been destroyed by mine countermeasures from {1}.",
                    //    UnitClass.UnitClassShortName, unit.ToShortString()));
                    //msg2.Position = unit.Position.Clone();

                    this.IsMarkedForDeletion = true;
                    return;
                }
                double distanceM = MapHelper.CalculateDistanceM(this.Position.Coordinate, unit.Position.Coordinate);
                if (distanceM <= GameConstants.MAX_MINE_IMPACT_RANGE_M)
                {
                    GameManager.Instance.Log.LogDebug(
                        string.Format("Mine->Tick() reports IMPACT between mine {0} and unit {1}", ToShortString(), unit.ToShortString()));
                    unit.InflictDamageFromProjectileHit(this);
                    this.IsMarkedForDeletion = true;
                    return;
                }
            }
        }
コード例 #9
0
        public TokenUnit(LiveUnit creator, OwnerPlayer owner, int health = 9999) : base(health, owner)
        {
            this.creator = creator;

            ownerPlayer = (creator == null? OwnerPlayer.None : creator.ownerPlayer);

            MovesLeft   = 0;
            hasAttacked = true;
            hasMoved    = true;

            //NOTE: logic does not support tokens owned by multiple players. can't see why we'd need them, so DON'T MAKE THEM!
            if (ownerPlayer != OwnerPlayer.None)
            {
                GetOwner().AddUnit(this);
            }
        }
コード例 #10
0
        public override void UnitHasNoMovementOrders(BaseUnit unit)
        {
            if (unit is AircraftUnit && unit.Position != null && !unit.IsMarkedForDeletion)
            {
                Coordinate coord = unit.Position.Coordinate;
                List <GameConstants.Role> roleList = new List <GameConstants.Role>();
                roleList.Add(GameConstants.Role.IsSurfaceCombattant);
                var nearestUnit = OwnerPlayer.FindNearestAvailableUnitRole(coord, roleList, string.Empty, false);

                if (nearestUnit != null)
                {
                    GameManager.Instance.Log.LogDebug(
                        string.Format("UnitHasNoMovementOrders: {0} has no movement orders: directed to airspace around unit {1}",
                                      unit, nearestUnit));
                    //Find nearest surface combattant and patrol area
                    var moveOrder = this.CreateSearchOrdersAircraft(
                        Region.FromCircle(coord, GameConstants.DEFAULT_AIR_ASu_STRIKE_RANGE_M),
                        unit.SupportsRole(GameConstants.Role.ASW), false);
                    unit.Orders.Enqueue(moveOrder);
                    unit.MissionType = GameConstants.MissionType.Patrol;
                }
                else
                {
                    //if no surface combattant, patrol near airport
                    roleList.Clear();
                    roleList.Add(GameConstants.Role.LaunchFixedWingAircraft);
                    nearestUnit = OwnerPlayer.FindNearestAvailableUnitRole(coord, roleList, string.Empty, false);
                    if (nearestUnit != null)
                    {
                        GameManager.Instance.Log.LogDebug(
                            string.Format("UnitHasNoMovementOrders: {0} has no movement orders: directed to airspace around airfield {1}",
                                          unit, nearestUnit));

                        var moveOrder = this.CreateSearchOrdersAircraft(
                            Region.FromCircle(coord, GameConstants.DEFAULT_AIR_ASu_STRIKE_RANGE_M),
                            false, false);
                        unit.Orders.Enqueue(moveOrder);
                        unit.MissionType = GameConstants.MissionType.Patrol;
                    }
                }//TODO: Look at AI hints when ready!
                unit.SetMissionStatusFromOrders();
                unit.IsOutOfAmmo();
            }
            //TODO: Also give orders to ships and subs!
            base.UnitHasNoMovementOrders(unit);
        }
コード例 #11
0
    public void OnClick_Agari()
    {
        if (isMenuEnable(EActionType.Ron) || isMenuEnable(EActionType.Tsumo))
        {
            //Debug.Log("+ OnClick_Agari()");

            if (PlayerAction.IsValidTsumo)
            {
                PlayerAction.Response = EResponse.Tsumo_Agari;
            }
            else
            {
                PlayerAction.Response = EResponse.Ron_Agari;
            }

            NotifyHide();
            OwnerPlayer.OnPlayerInputFinished();
        }
    }
コード例 #12
0
    public void Onclick_Nagashi()
    {
        if (isMenuEnable(EActionType.Nagashi) || isMenuEnable(EActionType.RyuuKyoku))
        {
            //Debug.Log("+ Onclick_Nagashi()");

            if (PlayerAction.State == EActionState.Select_Kan)  // enable Ankan after Reach.
            {
                PlayerAction.Response     = EResponse.SuteHai;
                PlayerAction.SutehaiIndex = OwnerPlayer.Tehai.getJyunTehaiCount();
            }
            else
            {
                PlayerAction.Response = EResponse.Nagashi;
            }

            NotifyHide();
            OwnerPlayer.OnPlayerInputFinished();
        }
    }
コード例 #13
0
ファイル: Building.cs プロジェクト: DCNick3/MineBotGame
 public ActionError DoOperation(BuildingOperation op)
 {
     if (OperationQueue.Count == QUEUE_SIZE)
     {
         return(ActionError.NoQueueSpace);
     }
     if (!OwnerPlayer.CheckResources(op.ResourceConsumation))
     {
         return(ActionError.NoResources);
     }
     if (!OwnerPlayer.CheckEnergy(op.EnergyConsumation))
     {
         return(ActionError.NoEnergy);
     }
     if (op.CanBeDone())
     {
         return(ActionError.InvalidParam);
     }
     op.StartOperation();//здесь снимаются ресурсы и энергия
     Enqueue(op);
     return(ActionError.Succeed);
 }
コード例 #14
0
ファイル: AircraftUnit.cs プロジェクト: JHaugland/WetAffairs
        public bool LandOnBase()
        {
            GameManager.Instance.Log.LogDebug(
                string.Format("AircraftUnit->LandOnBase: Unit {0}.", ToString()));

            SetDirty(GameConstants.DirtyStatus.UnitChanged);
            if (LaunchedFromUnit == null || LaunchedFromUnit.Position == null ||
                LaunchedFromUnit.IsMarkedForDeletion || LaunchedFromUnit.HitPoints <= 0)
            {
                if (!_hasSentCarrierLostMessage)
                {
                    _hasSentCarrierLostMessage = true;
                    SetHomeToNewCarrier();
                }
                return(false);
            }
            double distanceM = MapHelper.CalculateDistanceM(this.Position.Coordinate, LaunchedFromUnit.Position.Coordinate);

            if (distanceM > GameConstants.DISTANCE_TO_TARGET_IS_HIT_M * 3.0)
            {
                GameManager.Instance.Log.LogDebug(
                    string.Format("LandOnBase: {0} is {1:F}m away from {2}, reattempting ReturnToBase.",
                                  Id, distanceM, LaunchedFromUnit));
                this.IsOrderedToReturnToBase = false;
                return(ReturnToBase());
            }
            if (LaunchedFromUnit.AircraftHangar == null)
            {
                OwnerPlayer.Send(new GameStateInfo(GameConstants.GameStateInfoType.AircraftLandingFailed, this.Id, LaunchedFromUnit.Id));
                GameManager.Instance.Log.LogError(
                    string.Format("Unit{0} cannot land on unit {1} since it has no AircraftHangar",
                                  ToShortString(), LaunchedFromUnit.ToShortString()));
                SetHomeToNewCarrier();
                return(false);
            }
            if (LaunchedFromUnit.AircraftHangar.ReadyInSec > GameConstants.DEFAULT_TIME_BETWEEN_TAKEOFFS_SEC * 2) //it is damaged
            {
                TimeSpan time = TimeSpan.FromSeconds(LaunchedFromUnit.AircraftHangar.ReadyInSec);
                OwnerPlayer.Send(new GameStateInfo(GameConstants.GameStateInfoType.AircraftLandingFailed, this.Id, LaunchedFromUnit.Id));
                SetHomeToNewCarrier();
                return(false);
            }
            double CrashChancePercent       = 0;
            int    EffectiveLandingSeaState = LaunchedFromUnit.GetEffectiveSeaState();

            if (EffectiveLandingSeaState > GameConstants.AIRCRAFT_LANDING_MAX_SEA_STATE)
            {
                OwnerPlayer.Send(new GameStateInfo(GameConstants.GameStateInfoType.AircraftLandingFailed, this.Id, LaunchedFromUnit.Id));

                GameManager.Instance.Log.LogDebug(string.Format(
                                                      "LandOnBase: Unit {0} could not land due to rough weather. Max sea state is {1},"
                                                      + "effective sea state is {2}",
                                                      ToShortString(), GameConstants.AIRCRAFT_LANDING_MAX_SEA_STATE,
                                                      EffectiveLandingSeaState));
                return(false);
            }
            else if (GetEffectiveSeaState() == GameConstants.AIRCRAFT_LANDING_MAX_SEA_STATE)
            {
                CrashChancePercent = 25.0;
            }
            if (CrashChancePercent > 0 && GameManager.Instance.ThrowDice(CrashChancePercent))
            {
                IsMarkedForDeletion = true;
                OwnerPlayer.Send(new GameStateInfo(GameConstants.GameStateInfoType.AircraftCrashedOnLandingRoughWeather, this.Id, LaunchedFromUnit.Id));
                GameManager.Instance.Log.LogDebug(string.Format(
                                                      "LandOnBase: {0} CRASHED due to rough weather. Effective sea state is {1}", ToShortString(),
                                                      EffectiveLandingSeaState));
                return(false);
            }

            if (LaunchedFromUnit.UnitClass.CarriedRunwayStyle < this.UnitClass.RequiredRunwayStyle)
            {
                OwnerPlayer.Send(new GameStateInfo(GameConstants.GameStateInfoType.AircraftLandingFailed, this.Id, LaunchedFromUnit.Id));
                GameManager.Instance.Log.LogError(string.Format(
                                                      "LandOnBase: {0} cannot land on {1}: Requires {2}.", ToShortString(),
                                                      LaunchedFromUnit.ToShortString(), this.UnitClass.RequiredRunwayStyle));
                SetHomeToNewCarrier();
                return(false);
            }
            if (OwnerPlayer != null && OwnerPlayer.TcpPlayerIndex > 0)
            {
                //GameManager.Instance.Log.LogDebug("LandOnBase: Sending GameStateInfo object");
                OwnerPlayer.Send(new GameStateInfo()
                {
                    Id          = this.Id,
                    InfoType    = GameConstants.GameStateInfoType.AircraftIsLanded,
                    SecondaryId = LaunchedFromUnit.Id,
                    UnitClassId = this.UnitClass.Id,
                    BearingDeg  = (double)this.Position.BearingDeg,
                });
            }
            _hasSentCarrierLostMessage = false;
            CarriedByUnit = LaunchedFromUnit;
            _hasCheckedForNearestCarrier   = false;
            _hasSentActiveDetectionMessage = false;
            MovementOrder = null;
            Orders.Clear();
            IsOrderedToReturnToBase = false;
            TargetDetectedUnit      = null;
            Position = null;

            LaunchedFromUnit.AircraftHangar.Aircraft.Add(this);
            try
            {
                UnitClassWeaponLoads load = UnitClass.WeaponLoads.Single <UnitClassWeaponLoads>(l => l.Name == this.CurrentWeaponLoadName);
                if (load != null)
                {
                    ReadyInSec = load.TimeToReloadHour * 60 * 60;
                }
                else
                {
                    ReadyInSec = LaunchedFromUnit.AircraftHangar.GetStatusChangeTimeSec(
                        GameConstants.AircraftDockingStatus.TankingAndRefitting,
                        GameConstants.AircraftDockingStatus.ReadyForTakeoff);
                }
            }
            catch (Exception)
            {   //default reload time
                ReadyInSec = LaunchedFromUnit.AircraftHangar.GetStatusChangeTimeSec(
                    GameConstants.AircraftDockingStatus.TankingAndRefitting,
                    GameConstants.AircraftDockingStatus.ReadyForTakeoff);
            }
            MissionType            = GameConstants.MissionType.Patrol;
            MissionTargetType      = GameConstants.MissionTargetType.Undefined;
            AssignedHighLevelOrder = null;
            LaunchedFromUnit.SetDirty(GameConstants.DirtyStatus.UnitChanged);
            var wpnLoad = GameManager.Instance.GameData.GetWeaponLoadByName(UnitClass.Id, CurrentWeaponLoadName);

            if (wpnLoad != null)
            {
                bool isEnoughAmmoToReload = CanChangeToWeaponLoad(wpnLoad, false);
                if (!isEnoughAmmoToReload)
                {
                    SetWeaponLoad(string.Empty); //default
                }
                foreach (var weapon in Weapons)
                {
                    weapon.ReadyInSec          = 0;
                    weapon.IsOperational       = true;
                    weapon.AmmunitionRemaining = weapon.MaxAmmunition;
                }
            }
            foreach (var sensor in Sensors)
            {
                sensor.ReadyInSec    = 0;
                sensor.IsOperational = true;
                sensor.IsDamaged     = false;
                if (sensor.SensorClass.MaxSpeedDeployedKph > 0 || sensor.SensorClass.MaxHeightDeployedM > 0)
                {
                    sensor.IsOperational = false; //if sensor has height/speed restrictions, set non-operational
                }
                //sensor.IsActive = false;

                if (sensor.SensorClass.IsPassiveActiveSensor)
                {
                    sensor.IsActive = false;
                }
            }
            FuelDistanceCoveredSinceRefuelM = 0;
            if (_refuelingFromAircraft != null)
            {
                _refuelingFromAircraft.RemoveFromFuelQueue(this);
            }
            SetDirty(GameConstants.DirtyStatus.UnitChanged);
            return(true);
        }
コード例 #15
0
        public BlockItem(ItemManager itemManager, MasterRenderer renderer)
            : base(itemManager, ItemType.BlockItem)
        {
            this.renderer = renderer;

            ModelOffset            = new Vector3(-1.75f, -1.75f, 2.5f);
            ownerPlayerPhysicsBody = OwnerPlayer.GetComponent <PhysicsBodyComponent>();

            if (!GlobalNetwork.IsServer)
            {
                entRenderer = renderer.GetRenderer3D <EntityRenderer>();

                cube = new DebugCube(Color4.White, 1.5f);
                Renderer.VoxelObject = cube.VoxelObject;

                if (cursorCube == null)
                {
                    cursorCube = new DebugCube(Color4.White, Block.CUBE_SIZE);
                    cursorCube.RenderAsWireframe = true;
                    cursorCube.ApplyNoLighting   = true;
                    cursorCube.OnlyRenderFor     = RenderPass.Normal;
                }

                Colors = new Color[PaletteHeight, PaletteWidth];

                for (int y = 0; y < PaletteHeight; y++)
                {
                    for (int x = 0; x < PaletteWidth; x++)
                    {
                        if (y == 0)
                        {
                            Colors[y, x] = Maths.HSVToRGB(0, 0, Math.Max(x / (float)PaletteWidth, 0.05f));
                        }
                        else
                        {
                            int halfPalette = PaletteWidth / 2;
                            if (x > halfPalette)
                            {
                                Colors[y, x] = Maths.HSVToRGB(
                                    (y - 1) / ((float)PaletteHeight - 1) * 360,
                                    1f - Math.Max((x - halfPalette) / (float)halfPalette, 0.05f),
                                    1f);
                            }
                            else
                            {
                                Colors[y, x] = Maths.HSVToRGB(
                                    (y - 1) / ((float)PaletteHeight - 1) * 360,
                                    1f,
                                    Math.Max(x / (float)halfPalette, 0.05f));
                            }
                        }
                    }
                }

                BlockColor = Colors[ColorY, ColorX];

                if (!itemManager.IsReplicated)
                {
                    AudioBuffer buildAudioBuffer = AssetManager.LoadSound("Weapons/Block/build.wav");

                    if (buildAudioBuffer != null)
                    {
                        buildAudioSource = new AudioSource(buildAudioBuffer);
                        buildAudioSource.IsSourceRelative = true;
                        buildAudioSource.Gain             = 0.5f;
                    }
                }
            }
        }
コード例 #16
0
    public void OnClick_Kan()
    {
        if (isMenuEnable(EActionType.Kan))
        {
            //Debug.Log("+ OnClick_Kan()");

            if (PlayerAction.IsValidTsumoKan)
            {
                if (PlayerAction.TsumoKanHaiList.Count > 1)
                {
                    if (PlayerAction.State == EActionState.Select_Kan)    // cancel reach.
                    {
                        PlayerAction.State = EActionState.Select_Sutehai; // set state to Select_SuteHai

                        playerUI.Tehai.EnableInput(true);

                        //btn_Kan.SetTag( ResManager.getString("button_kan") );

                        // refresh other menu buttons
                        RefreshMenuButtons();
                    }
                    else
                    {
                        PlayerAction.State = EActionState.Select_Kan;

                        // list kan hai selection.
                        List <int> enableIndexList = new List <int>();
                        Hai[]      jyunTehais      = OwnerPlayer.Tehai.getJyunTehai();

                        for (int i = 0; i < PlayerAction.TsumoKanHaiList.Count; i++)
                        {
                            for (int j = 0; j < jyunTehais.Length; j++)
                            {
                                if (jyunTehais[j].ID == PlayerAction.TsumoKanHaiList[i].ID)
                                {
                                    enableIndexList.Add(j);
                                }
                            }
                        }

                        Hai tsumoHai = GameAgent.Instance.getTsumoHai();
                        for (int i = 0; i < PlayerAction.TsumoKanHaiList.Count; i++)
                        {
                            if (tsumoHai.ID == PlayerAction.TsumoKanHaiList[i].ID)
                            {
                                enableIndexList.Add(OwnerPlayer.Tehai.getJyunTehaiCount());
                            }
                        }

                        playerUI.Tehai.EnableInput(enableIndexList);

                        //btn_Kan.SetTag( ResManager.getString("button_cancel") );

                        // disable other menu buttons.
                        DisableButtonsExcept(EActionType.Kan);
                    }
                }
                else
                {
                    Hai kanHai = PlayerAction.TsumoKanHaiList[0];
                    OwnerPlayer.Action.KanSelectIndex = 0;

                    if (OwnerPlayer.Tehai.validKaKan(kanHai))
                    {
                        PlayerAction.Response = EResponse.Kakan;
                    }
                    else
                    {
                        PlayerAction.Response = EResponse.Ankan;
                    }

                    NotifyHide();
                    OwnerPlayer.OnPlayerInputFinished();
                }
            }
            else
            {
                PlayerAction.Response = EResponse.DaiMinKan;

                NotifyHide();
                OwnerPlayer.OnPlayerInputFinished();
            }
        }
    }
コード例 #17
0
        public void SearchForTarget(string targetId, string classId, bool doSensorSweep)
        {
            if (IsMarkedForDeletion)
            {
                return;
            }
            //first, see if targetdetectedunit is still known
            var targetDet = OwnerPlayer.GetDetectedUnitById(targetId);
            if (targetDet != null)
            {
                InterceptTarget(targetDet);
                return;
            }
            GameManager.Instance.Log.LogDebug(
                string.Format("MissileUnit->SearchForTarget Missile {0} looks for detid={1} or classid={2}",
                this.ToShortString(), targetId, classId));
            if (doSensorSweep && Sensors.Any())
            {
                if (UnitClass.UnitType == GameConstants.UnitType.Missile)
                {
                    SetSensorsActivePassive(GameConstants.SensorType.Radar, true);
                }
                else if (UnitClass.UnitType == GameConstants.UnitType.Torpedo)
                {
                    SetSensorsActivePassive(GameConstants.SensorType.Sonar, true);
                }
                this.SensorSweep();
            }

            //otherwise, see if target with same unitclass can be found. UnitClass in 
            var unitClassTarget = GameManager.Instance.GetUnitClassById(classId);

            // Get ordered list by distance of detected units within our fuel distance
            IEnumerable<DetectedUnit> detectedUnitsOrdered;

            // Filter out targets outside the max search sector range
            if (MaxSectorRangeSearchDeg < 360)
            {
                var bearing = ActualBearingDeg.HasValue ? ActualBearingDeg.Value : 0.0;
                var maxDistanceM = FuelDistanceRemainingM;

                if (TargetPosition != null)
                {
                    bearing = MapHelper.CalculateBearingDegrees(Position.Coordinate, TargetPosition.Coordinate);
                    maxDistanceM = MapHelper.CalculateDistanceRoughM(Position.Coordinate, TargetPosition.Coordinate);
                }

                detectedUnitsOrdered = from d in OwnerPlayer.DetectedUnits
                                       where !d.IsMarkedForDeletion && d.Position != null && d.CanBeTargeted
                                       && MapHelper.IsWithinSector(Position.Coordinate, bearing,
                                                      MaxSectorRangeSearchDeg, d.Position.Coordinate)
                                       let distanceToTargetM = MapHelper.CalculateDistance3DM(d.Position, this.Position)
                                       where distanceToTargetM <= maxDistanceM
                                       orderby distanceToTargetM ascending
                                       select d;
            }
            else
            {
                detectedUnitsOrdered = from d in OwnerPlayer.DetectedUnits
                                       where !d.IsMarkedForDeletion && d.Position != null && d.CanBeTargeted
                                       let distanceToTargetM = MapHelper.CalculateDistance3DM(d.Position, this.Position)
                                       where distanceToTargetM <= FuelDistanceRemainingM
                                       orderby distanceToTargetM ascending
                                       select d;
            }

            //var weaponClass = GameManager.Instance.GetWeaponClassById(this.WeaponClassId);
            foreach (var det in detectedUnitsOrdered)
            {
                if (unitClassTarget != null)
                {
                    if (det.IsIdentified && det.RefersToUnit != null)
                    {
                        if (det.RefersToUnit.UnitClass.Id == unitClassTarget.Id)
                        {
                            InterceptTarget(det);
                            return;
                        }
                    }
                    else
                    {
                        if (LaunchWeapon != null
                            && det.RefersToUnit != null
                            && LaunchWeapon.CanTargetDetectedUnit(det.RefersToUnit, true))
                        {
                            InterceptTarget(det);
                            return;
                        }
                    }
                }
                else if (this.LaunchWeapon != null && this.LaunchWeapon.CanTargetDetectedUnit(det, true))
                {
                    InterceptTarget(det);
                    return;
                }
            }
            if (TargetDetectedUnit == null || TargetDetectedUnit.IsMarkedForDeletion)
            {
                if (MovementOrder != null && MovementOrder.CountWaypoints == 1)
                {
                    var wp = MovementOrder.PeekNextWaypoint();
                    if (MapHelper.CalculateDistance3DM(Position, wp.Position) < GameConstants.DISTANCE_TO_TARGET_IS_HIT_M)
                    {
                        GameManager.Instance.Log.LogDebug(string.Format("SearchForTarget: Missile {0} waypoint was close: deleted.", this));
                        MovementOrder = null;
                        //this.ActiveWaypoint = null;
                    }
                }
            }
            if ((TargetDetectedUnit == null || TargetDetectedUnit.IsMarkedForDeletion)
                && (MovementOrder == null || MovementOrder.CountWaypoints == 0 || GetActiveWaypoint() == null)) //can't find anything. self-destruct
            {
                GameManager.Instance.Log.LogDebug(
                    string.Format("MissileUnit->SearchForTarget Missile {0} found no target and is being deleted.",
                    this.ToShortString()));

                this.IsMarkedForDeletion = true;
            }
        }
コード例 #18
0
 //Constructor
 public Player(OwnerPlayer num)
 {
     this.playerNum = num;
     Units          = new List <LiveUnit>();
 }
コード例 #19
0
 protected void CheckFriendOrFoeStatus(DetectedUnit detectedUnit)
 {
     if (detectedUnit.IsIdentified && detectedUnit.RefersToUnit != null)
     {
         if (detectedUnit.FriendOrFoeClassification == GameConstants.FriendOrFoe.Foe && !OwnerPlayer.IsEnemy(detectedUnit.RefersToUnit.OwnerPlayer))
         {
             detectedUnit.FriendOrFoeClassification = GameConstants.FriendOrFoe.Undetermined;
         }
     }
 }
コード例 #20
0
ファイル: TehaiUI.cs プロジェクト: iuvei/mahjong3d
    void OnClickMahjong()
    {
        //Debug.Log ("OnClickMahjong()");
        int index = tehaiList.IndexOf(MahjongPai.current);

        //int index = 0;
        //Debug.Log("OnClickMahjong(" + index.ToString()+")");
        //index = OwnerPlayer.Tehai.getJyunTehaiCount() - 1; // Test: the last one.

        switch (PlayerAction.State)
        {
        case EActionState.Select_Agari:
        case EActionState.Select_Sutehai:
        {    //丟牌
            PlayerAction.Response     = EResponse.SuteHai;
            PlayerAction.SutehaiIndex = index;

            EventManager.Instance.RpcSendEvent(UIEventType.HideMenuList);
            OwnerPlayer.OnPlayerInputFinished();
        }
        break;

        case EActionState.Select_Reach:
        {    //聽牌
            PlayerAction.Response         = EResponse.Reach;
            PlayerAction.ReachSelectIndex = PlayerAction.ReachHaiIndexList.FindIndex(i => i == index);

            SetEnableStateColor(true);
            EventManager.Instance.RpcSendEvent(UIEventType.HideMenuList);
            OwnerPlayer.OnPlayerInputFinished();
        }
        break;

        case EActionState.Select_Kan:
        {    //槓
            Hai kanHai = new Hai(MahjongPai.current.ID);
            //Hai kanHai = new Hai( 0);

            if (OwnerPlayer.Tehai.validKaKan(kanHai))
            {
                PlayerAction.Response = EResponse.Kakan;
            }
            else
            {
                PlayerAction.Response = EResponse.Ankan;
            }

            PlayerAction.KanSelectIndex = PlayerAction.TsumoKanHaiList.FindIndex(h => h.ID == kanHai.ID);

            SetEnableStateColor(true);
            EventManager.Instance.RpcSendEvent(UIEventType.HideMenuList);
            OwnerPlayer.OnPlayerInputFinished();
        }
        break;

        case EActionState.Select_Chii:
        {    //吃
            MahjongPai curSelect = MahjongPai.current;
            //MahjongPai curSelect = new MahjongPai();

            if (chiiPaiSelectList.Contains(curSelect))
            {
                chiiPaiSelectList.Remove(curSelect);
                curSelect.transform.localPosition -= SelectStatePosOffset;

                // check to enable select other chii type pai.
                List <int> enableIndexList = new List <int>();
                Hai[]      jyunTehais      = OwnerPlayer.Tehai.getJyunTehai();

                for (int i = 0; i < PlayerAction.AllSarashiHais.Count; i++)
                {
                    for (int j = 0; j < jyunTehais.Length; j++)
                    {
                        if (jyunTehais[j].ID == PlayerAction.AllSarashiHais[i].ID)
                        {
                            enableIndexList.Add(j);
                        }
                    }
                }

                EnableInput(enableIndexList);
            }
            else
            {
                chiiPaiSelectList.Add(curSelect);
                if (curSelect)
                {
                    curSelect.transform.localPosition += SelectStatePosOffset;
                }

                if (chiiPaiSelectList.Count >= 2)      // confirm Chii.
                {
                    chiiPaiSelectList.Sort(MahjongPaiCompare);

                    if (PlayerAction.SarashiHaiRight.Count >= 2)
                    {
                        PlayerAction.SarashiHaiRight.Sort(Tehai.Compare);
                        if (chiiPaiSelectList[0].ID == PlayerAction.SarashiHaiRight[0].ID &&
                            chiiPaiSelectList[1].ID == PlayerAction.SarashiHaiRight[1].ID)
                        {
                            PlayerAction.Response       = EResponse.Chii_Right;
                            PlayerAction.ChiiSelectType = PlayerAction.Chii_Select_Right;
                            Debug.Log("Chii type is Chii_Right");
                        }
                    }

                    if (PlayerAction.SarashiHaiCenter.Count >= 2)
                    {
                        PlayerAction.SarashiHaiCenter.Sort(Tehai.Compare);
                        if (chiiPaiSelectList[0].ID == PlayerAction.SarashiHaiCenter[0].ID &&
                            chiiPaiSelectList[1].ID == PlayerAction.SarashiHaiCenter[1].ID)
                        {
                            PlayerAction.Response       = EResponse.Chii_Center;
                            PlayerAction.ChiiSelectType = PlayerAction.Chii_Select_Center;
                            Debug.Log("Chii type is Chii_Center");
                        }
                    }

                    if (PlayerAction.SarashiHaiLeft.Count >= 2)
                    {
                        PlayerAction.SarashiHaiLeft.Sort(Tehai.Compare);
                        if (chiiPaiSelectList[0].ID == PlayerAction.SarashiHaiLeft[0].ID &&
                            chiiPaiSelectList[1].ID == PlayerAction.SarashiHaiLeft[1].ID)
                        {
                            PlayerAction.Response       = EResponse.Chii_Left;
                            PlayerAction.ChiiSelectType = PlayerAction.Chii_Select_Left;
                            Debug.Log("Chii type is Chii_Left");
                        }
                    }

                    EventManager.Instance.RpcSendEvent(UIEventType.HideMenuList);
                    OwnerPlayer.OnPlayerInputFinished();

                    chiiPaiSelectList.Clear();
                }
                else     // check to disable select other chii type pai.
                {
                    List <int> enableIndexList = new List <int>();
                    Hai[]      jyunTehais      = OwnerPlayer.Tehai.getJyunTehai();

                    int curSelectID = chiiPaiSelectList[0].ID;
                    enableIndexList.Add(index);

                    if (PlayerAction.SarashiHaiRight.Exists(h => h.ID == curSelectID))
                    {
                        Hai otherHai = PlayerAction.SarashiHaiRight.Find(h => h.ID != curSelectID);

                        for (int i = 0; i < jyunTehais.Length; i++)
                        {
                            if (jyunTehais[i].ID == otherHai.ID && !enableIndexList.Contains(i))
                            {
                                enableIndexList.Add(i);
                            }
                        }
                    }

                    if (PlayerAction.SarashiHaiCenter.Exists(h => h.ID == curSelectID))
                    {
                        Hai otherHai = PlayerAction.SarashiHaiCenter.Find(h => h.ID != curSelectID);

                        for (int i = 0; i < jyunTehais.Length; i++)
                        {
                            if (jyunTehais[i].ID == otherHai.ID && !enableIndexList.Contains(i))
                            {
                                enableIndexList.Add(i);
                            }
                        }
                    }

                    if (PlayerAction.SarashiHaiLeft.Exists(h => h.ID == curSelectID))
                    {
                        Hai otherHai = PlayerAction.SarashiHaiLeft.Find(h => h.ID != curSelectID);

                        for (int i = 0; i < jyunTehais.Length; i++)
                        {
                            if (jyunTehais[i].ID == otherHai.ID && !enableIndexList.Contains(i))
                            {
                                enableIndexList.Add(i);
                            }
                        }
                    }

                    EnableInput(enableIndexList);
                }
            }
        }
        break;
        }
    }
コード例 #21
0
    public void OnClick_Chii()
    {
        if (isMenuEnable(EActionType.Chii))
        {
            //Debug.Log("+ OnClick_Chii()");

            if (PlayerAction.AllSarashiHais.Count > 2)
            {
                if (PlayerAction.State == EActionState.Select_Chii) // cancel reach.
                {
                    PlayerAction.State = EActionState.None;         // set state to Select_SuteHai

                    playerUI.Tehai.EnableInput(true);

                    //btn_Chii.SetTag( ResManager.getString("button_chii") );

                    // refresh other menu buttons
                    RefreshMenuButtons();
                }
                else
                {
                    PlayerAction.State = EActionState.Select_Chii;

                    // list chii hai selection.
                    List <int> enableIndexList = new List <int>();
                    Hai[]      jyunTehais      = OwnerPlayer.Tehai.getJyunTehai();

                    for (int i = 0; i < PlayerAction.AllSarashiHais.Count; i++)
                    {
                        for (int j = 0; j < jyunTehais.Length; j++)
                        {
                            if (jyunTehais[j].ID == PlayerAction.AllSarashiHais[i].ID)
                            {
                                enableIndexList.Add(j);
                            }
                        }
                    }

                    playerUI.Tehai.EnableInput(enableIndexList);

                    //btn_Chii.SetTag( ResManager.getString("button_cancel") );

                    // disable other menu buttons.
                    DisableButtonsExcept(EActionType.Chii);
                }
            }
            else
            {
                // check Chii type.
                if (PlayerAction.IsValidChiiLeft)
                {
                    PlayerAction.Response = EResponse.Chii_Left;
                }
                else if (PlayerAction.IsValidChiiCenter)
                {
                    PlayerAction.Response = EResponse.Chii_Center;
                }
                else
                {
                    PlayerAction.Response = EResponse.Chii_Right;
                }

                PlayerAction.ChiiSelectType = 0;

                NotifyHide();
                OwnerPlayer.OnPlayerInputFinished();
            }
        }
    }
コード例 #22
0
ファイル: BaseSensor.cs プロジェクト: JHaugland/WetAffairs
        public virtual DetectedUnit CreateOrUpdateDetectionReport(BaseUnit unit,
                                                                  double detectionStrength, double distanceM, double targetApparentSizeArcSec, double minDetectableSizeArcSec)
        {
            DetectedUnit       detect = OwnerPlayer.DetectedUnits.Find(d => d.RefersToUnit.Id == unit.Id);
            DetectedUnitSensor sensor;

            if (detect != null) //detected previously
            {
                detect.IsMarkedForDeletion = false;
                sensor = detect.AddOrUpdateSensor(unit, this, detectionStrength, distanceM,
                                                  targetApparentSizeArcSec, minDetectableSizeArcSec);
                detect.DetectedGameWorldTimeSec = GameManager.Instance.Game.GameWorldTimeSec;
                if (!unit.Position.Equals(detect.Position))
                {
                    detect.SetDirty(GameConstants.DirtyStatus.PositionOnlyChanged);
                    if (detect.IsFixed)
                    {
                        detect.Position = unit.Position.Clone(); //TODO: Add uncertainty if applicable
                    }
                }
                if (unit.DirtySetting == GameConstants.DirtyStatus.UnitChanged)
                {
                    detect.SetDirty(GameConstants.DirtyStatus.UnitChanged);
                }

                if (detectionStrength >= SensorClass.IdentifyDetectionStrength &&
                    !detect.IsFixed && !detect.IsIdentified)
                {
                    detect.IsFixed      = true;
                    detect.IsIdentified = true;
                    detect.SetDirty(GameConstants.DirtyStatus.UnitChanged);
                    if (this.OwnerPlayer.IsEnemy(unit.OwnerPlayer))
                    {
                        detect.FriendOrFoeClassification = GameConstants.FriendOrFoe.Foe;
                    }
                    else if (OwnerPlayer.IsAlly(unit.OwnerPlayer))
                    {
                        detect.FriendOrFoeClassification = GameConstants.FriendOrFoe.Friend;
                    }
                    GameManager.Instance.Log.LogDebug("CreateOrUpdateDetectionReport: UPDATE: " + detect.ToLongString());
                }
                if (detect.IsIdentified)
                {
                    if (this.OwnerPlayer.IsEnemy(unit.OwnerPlayer))
                    {
                        detect.FriendOrFoeClassification = GameConstants.FriendOrFoe.Foe;
                    }
                    else if (OwnerPlayer.IsAlly(unit.OwnerPlayer))
                    {
                        detect.FriendOrFoeClassification = GameConstants.FriendOrFoe.Friend;
                    }
                    //detect.SetDirty(GameConstants.DirtyStatus.UnitChanged);
                }
                if (OwnerPlayer.AIHandler != null && detect.DirtySetting == GameConstants.DirtyStatus.UnitChanged)
                {
                    OwnerPlayer.AIHandler.DetectionUpdated(detect);
                }
                return(detect); //otherwise unchanged
            }
            //NEW DETECTION:
            detect             = new DetectedUnit();
            detect.OwnerPlayer = this.OwnerPlayer;

            detect.ThreatClassification = GameConstants.ThreatClassification.U_Undecided;
            sensor = detect.AddOrUpdateSensor(unit, this, detectionStrength, distanceM,
                                              targetApparentSizeArcSec, minDetectableSizeArcSec);
            if (!unit.UnitClass.CanBeTargeted)
            {
                detect.CanBeTargeted = false;
            }
            if (detect.IsIdentified)
            {
                if (this.OwnerPlayer.IsEnemy(unit.OwnerPlayer))
                {
                    detect.FriendOrFoeClassification = GameConstants.FriendOrFoe.Foe;
                }
                else
                {
                    if (this.OwnerPlayer.IsAlly(unit.OwnerPlayer))
                    {
                        detect.FriendOrFoeClassification = GameConstants.FriendOrFoe.Friend;
                    }
                }
            }
            if (detect.FriendOrFoeClassification == GameConstants.FriendOrFoe.Undetermined)
            {
                if (detect.RefersToUnit != null && detect.RefersToUnit.UnitClass.IsMissileOrTorpedo) //missiles assumed hostile
                {
                    if (!this.OwnerPlayer.IsAlly(unit.OwnerPlayer))
                    {
                        detect.FriendOrFoeClassification = GameConstants.FriendOrFoe.Foe;
                    }
                }
                if (detect.FriendOrFoeClassification == GameConstants.FriendOrFoe.Undetermined &&
                    !detect.IsIdentified &&
                    OwnerPlayer.IsAllUnknownContactsHostile)
                {
                    detect.FriendOrFoeClassification = GameConstants.FriendOrFoe.Foe;
                }
            }
            GameManager.Instance.Log.LogDebug(string.Format(
                                                  "CreateOrUpdateDetectionReport NEW Player: {0}: Detection {1} ",
                                                  OwnerPlayer.ToString(), detect.ToLongString()));

            if (!this.SensorClass.IsTargetingSensorOnly)
            {
                OwnerPlayer.DetectedUnits.Add(detect);
            }
            detect.SetDetectedGroup();
            if (OwnerPlayer.AIHandler != null)
            {
                OwnerPlayer.AIHandler.NewDetection(detect);
            }
            return(detect);
        }