Example #1
0
 void RpcSendMessageToFaction(Message message, FactionName faction)
 {
     if (faction == PlayerManager.GetPlayerManager.Player.Faction)
     {
         AddMessageToList(message);
     }
 }
Example #2
0
        public bool fire(Transform barrelEnd, Transform barrelStart, FactionName factionThatFiredShot, bool isAiming = false)
        {
            //print (fireModes.Length);
            if (magazines.Count != 0)
            {
                currentMag = currentMag % magazines.Count;
            }
            else
            {
                currentMag = 0;
            }
            if (stateOfWeapon == WeaponState.Ready && magazines.Count > 0)
            {
                magazines[currentMag] -= fireModes [currentFireMode].fire(barrelEnd.position, barrelStart.position, magazines[currentMag], factionThatFiredShot, isAiming);
                if (!discardOnFire && magazines[currentMag] <= 0)
                {
                    magazines.RemoveAt(currentMag);
                    if (magazines.Count > 0)
                    {
                        currentMag = currentMag % magazines.Count;
                    }
                    return(true);
                }
            }
            else
            {
                //print ()
            }



            return(false);
        }
Example #3
0
        public bool fire(FactionName factionThatFiredShot, bool isAiming = false, bool fireButtonHeldDown = true, bool fireButtonPressed = false)
        {
            if (enabled && weapon.willFire(fireButtonHeldDown, fireButtonPressed))
            {
                if ((Time.time - timeWhenLastSoundWasRemoved) > soundRemovalInterval && numSounds > 0)
                {
                    timeWhenLastSoundWasRemoved = Time.time;
                    numSounds -= 1;
                }
                if (fireSoundSource != null && fireSound != null && weapon.magazines.Count > 0 && weapon.magazines[weapon.currentMag] > 0 && numSounds < maxNumSounds)
                {
                    fireSoundSource.PlayOneShot(fireSound);
                    numSounds += 1;
                }
                bool result = weapon.fire(barrelEnd, barrelStart, factionThatFiredShot, isAiming);
                if (weapon.discardOnFire && weapon.stateOfWeapon != WeaponState.Dropped)
                {
                    weapon.stateOfWeapon = WeaponState.Dropped;
                    weapon.dropWeapon(barrelEnd.position);
                    //gameObject.rem
                }
                return(result);
            }

            return(false);
        }
Example #4
0
        /// <summary>
        /// 寻找周围的能量建筑 不包括GaiaBuilding
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public List <Tuple <int, int> > GetSurroundhexWithBuild(int x, int y, FactionName name, int?dis = null)
        {
            //吸能量大小范围
            var ret      = new List <Tuple <int, int> >();
            int distance = 0;

            if (dis.HasValue)
            {
                distance = dis.Value;
            }
            else
            {
                distance = 1;
            }
            for (int i = Math.Max(x - distance, 0); i <= Math.Min(x + distance, m_mapHeight - 1); i++)
            {
                for (int j = Math.Max(y - distance, 0); j <= Math.Min(j + distance, m_mapWidth - 1); j++)
                {
                    if (CalTwoHexDistance(x, y, i, j) <= distance)
                    {
                        //System.Diagnostics.Debug.WriteLine("row:" + i + " col:" + j);

                        if ((HexArray[i, j] != null && HexArray[i, j].FactionBelongTo == name && !(HexArray[i, j].Building is GaiaBuilding)) ||
                            (name == FactionName.Lantida && HexArray[i, j] != null && HexArray[i, j].SpecialBuilding != null))
                        {
                            ret.Add(new Tuple <int, int>(i, j));
                        }
                    }
                }
            }
            return(ret);
        }
Example #5
0
        public bool AIfire(FactionName factionThatFiredShot, Vector3 barrelStart, Vector3 barrelEnd, bool isAiming = false)
        {
            if (enabled)
            {
                if (weapon.getCurrentFireMode().timeSinceLastShot > weapon.getCurrentFireMode().fireRate)
                {
                    if ((Time.time - timeWhenLastSoundWasRemoved) > soundRemovalInterval && numSounds > 0)
                    {
                        timeWhenLastSoundWasRemoved = Time.time;
                        numSounds -= 1;
                    }
                    if (fireSoundSource != null && fireSound != null && weapon.magazines.Count > 0 && weapon.magazines [weapon.currentMag] > 0 && numSounds < maxNumSounds)
                    {
                        fireSoundSource.PlayOneShot(fireSound);
                        numSounds += 1;
                    }
                }
                //barrelEnd.position +=startBarrelOffset;
                bool result = weapon.fire(barrelEnd, barrelStart, factionThatFiredShot, isAiming);
                //barrelStart.position-=startBarrelOffset;
                if (weapon.discardOnFire && weapon.stateOfWeapon != WeaponState.Dropped)
                {
                    weapon.stateOfWeapon = WeaponState.Dropped;
                    weapon.dropWeapon(barrelEnd);
                    //gameObject.rem
                }
                return(result);
            }

            return(false);
        }
Example #6
0
        /// <summary>
        /// 寻找周围的空的能放卫星的格子
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="name"></param>
        /// <param name="dis"></param>
        /// <returns></returns>
        public List <Tuple <int, int> > GetSurroundhex(int x, int y, FactionName name, List <Tuple <int, int> > list)
        {
            //吸能量大小范围
            var ret      = new List <Tuple <int, int> >();
            int distance = 1;

            for (int i = Math.Max(x - distance, 0); i <= Math.Min(x + distance, m_mapHeight - 1); i++)
            {
                for (int j = Math.Max(y - distance, 0); j <= Math.Min(j + distance, m_mapWidth - 1); j++)
                {
                    if (CalTwoHexDistance(x, y, i, j) <= distance)
                    {
                        if (HexArray[i, j] != null && HexArray[i, j].TFTerrain == Terrain.Empty && !HexArray[i, j].Satellite.Contains(name))
                        {
                            var surroundHex = GetSurroundhexWithBuildingAndSatellite(i, j, name);
                            surroundHex.RemoveAll(z => list.Contains(z));
                            if (surroundHex.Count == 0)
                            {
                                ret.Add(new Tuple <int, int>(i, j));
                            }
                        }
                    }
                }
            }
            return(ret);
        }
Example #7
0
        public Player(string name, FactionName faction)
        {
            this.Name = name;
            this.Score = 0;
            switch (faction)
            {
                case FactionName.Dwarves:
                    this.CurrentFaction = new DwarvesFaction();
                    break;

                case FactionName.Gauls:
                    this.CurrentFaction = new GaulsFaction();
                    break;

                case FactionName.Vikings:
                    this.CurrentFaction = new VikingsFaction();
                    break;

                default:
                    throw new NotImplementedException();
            }

            if (Name.StartsWith("AI-")) // Artificial Intelligence
            {
                isAI = true;
                aiTimer = new System.Windows.Threading.DispatcherTimer();
                aiTimer.Tick += new EventHandler(aiLogic_Tick);
                aiTimer.Interval = new TimeSpan(0, 0, 0, 0, 500);
            }
        }
Example #8
0
        public IActionResult LeechPower(string name, FactionName factionName, int power, FactionName leechFactionName, bool isLeech, bool?isPwFirst)
        {
            if (ServerStatus.IsStopSyntax == true)
            {
                return(Redirect("/home/serverdown"));
            }
            var task = _userManager.GetUserAsync(HttpContext.User);

            Task[] taskarray = new Task[] { task };
            Task.WaitAll(taskarray, millisecondsTimeout: 1000);
            var faction = GameMgr.GetGameByName(name).FactionList.Find(x => x.FactionName.ToString().Equals(name));
            var leech   = isLeech ? "leech" : "decline";

            var syntax = string.Format("{0}:{1} {2} from {3}", factionName, leech, power, leechFactionName);

            if (isPwFirst.HasValue)
            {
                var pwFirst = isPwFirst.GetValueOrDefault() ? "pw" : "pwt";
                syntax = syntax + " " + pwFirst;
            }
            GaiaGame gaiaGame = GameMgr.GetGameByName(name);

            try
            {
                //GameMgr.WriteUserActionLog(syntax, task.Result.UserName);
            }
            catch { }
            gaiaGame.Syntax(syntax, out string log, dbContext: this.dbContext);
            //如果是即时制游戏,进行通知
            if (gaiaGame.IsSocket)
            {
                NoticeWebSocketMiddleware.GameActive(gaiaGame, HttpContext.User);
            }
            return(Redirect("/home/viewgame/" + System.Net.WebUtility.UrlEncode(name)));
        }
Example #9
0
 public void AddSatellite(FactionName factionName)
 {
     if (Satellite != null)
     {
         Satellite.Add(factionName);
     }
 }
        /*
         * This method damages a object, then it's parents. If the health is <=0 and the object should be destroyed when it dies (runs out of health) it is destroyed and a random death sound is played
         */
        public virtual bool damage(float amount, FactionName factionThatFiredShot = FactionName.NONE,
                                   Vector3 shotDirection = default(Vector3))
        {
            if (canBeDamaged && (c_soldierEntity.entity == null || c_soldierEntity.entity.faction != factionThatFiredShot))
            {
                health -= amount;

                for (int i = 0; i < eventsToCallOnDamage.Count; ++i)
                {
                    eventsToCallOnDamage [i] (this, amount, factionThatFiredShot, shotDirection);
                }

                if (parent != null)
                {
                    parent.damage(amount, factionThatFiredShot, shotDirection);
                }
            }

            if (health <= 0 && destroyOnDeath)
            {
                GameObject.Destroy(gameObject);
                if (audioClipsToPlayOnDeath != null && audioClipsToPlayOnDeath.Length > 0)
                {
                    AudioSource.PlayClipAtPoint(audioClipsToPlayOnDeath[(int)UnityEngine.Random.Range(0,
                                                                                                      audioClipsToPlayOnDeath.Length - 1)], gameObject.transform.position);
                }
                return(false);
            }
            return(true);
        }
Example #11
0
        public static FactionComponent Create(FactionName faction)
        {
            var component = new FactionComponent();

            component.Faction = faction;

            return(component);
        }
Example #12
0
        public Region(IMap map, Stack <string> baddieNames, FactionName stockBaddieFaction, bool isNebulae = false)
        {
            this.Empty = true;
            this.Map   = map;
            this.Name  = String.Empty;

            this.Create(baddieNames, stockBaddieFaction, isNebulae);
        }
        public Faction FactionDetails(FactionName faction)
        {
            this.Reset();

            var factionElement = this.Get.Factions[faction.ToString()];

            return(factionElement);
        }
Example #14
0
 public SoldierEntity(/*Collider[] CollidersForOtherSoldiersToCheckFor,*/ Transform [] LOSCheckTransforms, Collider[] LOSCheckColliders, FactionName faction, CharacterController mainLOSCollider, Transform centreOfMass)
 {
     //this.CollidersForOtherSoldiersToCheckFor = CollidersForOtherSoldiersToCheckFor;
     this.LOSCheckTransforms = LOSCheckTransforms;
     this.LOSCheckColliders  = LOSCheckColliders;
     this.faction            = faction;
     this.mainLOSCollider    = mainLOSCollider;
     this.centreOfMass       = centreOfMass;
 }
Example #15
0
 public static FactionName [] ActiveFactions()
 {
     FactionName[] activeFactions = new FactionName[Factions.Count];
     for (int i = 0; i < Factions.Count; ++i)
     {
         activeFactions [i] = Factions [i].FactionName;
     }
     return(activeFactions);
 }
Example #16
0
        public Map(SetupOptions setupOptions, IOutputWrite write, IStarTrekKGSettings config, FactionName defaultHostile = null)
        {
            this.Config = config;
            this.Write  = write;

            this.DefaultHostile = defaultHostile ?? FactionName.Klingon;

            this.Initialize(setupOptions);
        }
Example #17
0
        public void Create(Stack <string> baddieNames, FactionName stockBaddieFaction, bool addStars = true,
                           bool makeNebulae = false)
        {
            if (this.Map == null)
            {
                throw new GameException("Set Map before calling this function");
            }

            this.InitializeSectors(this, new List <Sector>(), baddieNames, stockBaddieFaction, addStars, makeNebulae);
        }
Example #18
0
        public static List <Entity> AdjacentHostiles(EncounterState state, FactionName parentFaction, EncounterPosition position)
        {
            var adjacentHostiles = new List <Entity>();

            foreach (var newpos in state.AdjacentPositions(position))
            {
                adjacentHostiles.AddRange(AIUtils.HostilesInPosition(state, parentFaction, newpos.X, newpos.Y));
            }
            return(adjacentHostiles);
        }
Example #19
0
 /// <summary>
 /// Method to be used as event for when agent is damaged
 /// </summary>
 /// <param name="healthController">Health controller.</param>
 /// <param name="damage">Damage.</param>
 /// <param name="factionThatFiredShot">Faction that fired shot.</param>
 /// <param name="shotDirection">Shot direction.</param>
 public bool OnDamage(ControlHealth healthController, float damage, FactionName factionThatFiredShot, Vector3 shotDirection)
 {
     if (healthController.health <= 0)
     {
         Debug.Assert(GameData.scores.ContainsKey(factionThatFiredShot));
         ++GameData.scores [factionThatFiredShot];
         Respawn();
     }
     return(false);
 }
Example #20
0
 public int CalShipDistanceNeed(int row, int col, FactionName factionName)
 {
     for (int i = 1; i < m_mapHeight; i++)
     {
         if (CalIsBuildValidate(row, col, factionName, i))
         {
             return(i);
         }
     }
     throw new Exception("无法结算航海距离");
 }
        public List <string> FactionShips(FactionName faction) //todo: this is called multiple times, do we need to reload file?
        {
            this.Reset();

            var factionElement = this.Get.Factions[faction.ToString()];

            FactionShips factionShips = factionElement.FactionShips;
            var          shipNames    = (from RegistryNameTypeClass shipElement in factionShips select shipElement.name.Trim()).ToList();

            return(shipNames);
        }
        //used by AI, so that intelligent entities can respond to near misses. Needs empty body since we can't make method abstract
        public virtual void suppress(float damage, FactionName factionThatFiredShot = FactionName.NONE, Vector3 shotDirection = default(Vector3))
        {
            float timeRatio = 1f / (1f + Time.time - lastSuppressionTime);             //must add one to ensure that ratio is <=1

            suppressionLevel    = (1f - timeRatio) * (damage / maxhealth) + timeRatio * suppressionLevel;
            lastSuppressionTime = Time.time;
            if (parent != null)
            {
                parent.suppress(damage * weighting, factionThatFiredShot, shotDirection);
            }
        }
Example #23
0
 public static void RemoveFaction(FactionName factionName)
 {
     for (int i = 0; i < Factions.Count; ++i)
     {
         if (Factions [i].FactionName == factionName)
         {
             Factions.RemoveAt(i);
             --i;
         }
     }
 }
Example #24
0
 public static Faction getFaction(FactionName factionToGet)
 {
     for (int i = 0; i < Factions.Count; i++)
     {
         if (Factions[i].FactionName == factionToGet)
         {
             return(Factions[i]);
         }
     }
     //Factions.Add(new Faction(factionToGet));
     return(Factions[Factions.Count - 1]);
 }
Example #25
0
 public OrderTrigger(OrderTriggerType triggerType, bool repeating, List <string> watchedUnitIds = null,
                     List <UnitOrder> awaitedStandingOrders = null, float belowStrengthPercent        = 9999,
                     FactionName triggerFaction             = FactionName.NEUTRAL, int activateOnTurn = -1)
 {
     this.TriggerType           = triggerType;
     this.Repeating             = repeating;
     this.WatchedUnitIds        = watchedUnitIds;
     this.AwaitedStandingOrders = awaitedStandingOrders;
     this.BelowStrengthPercent  = belowStrengthPercent;
     this.TriggerFaction        = triggerFaction;
     this.ActivateOnTurn        = activateOnTurn;
 }
Example #26
0
        private static void TryAddAttackAdjacent(EncounterState state, Entity parent, List <EncounterAction> actions,
                                                 FactionName parentFaction, EncounterPosition targetEndPos)
        {
            var adjacentHostiles = AIUtils.AdjacentHostiles(state, parentFaction, targetEndPos);

            if (adjacentHostiles.Count > 0)
            {
                // TODO: don't attack randomly
                var target = adjacentHostiles[state.EncounterRand.Next(adjacentHostiles.Count)];
                actions.Add(new MeleeAttackAction(parent.EntityId, target));
            }
        }
Example #27
0
        public static int getNumEnemyEntities(FactionName faction)
        {
            int result = 0;

            for (int i = 0; i < Factions.Count; i++)
            {
                if (Factions[i].FactionName != faction)
                {
                    result += Factions[i].Soldiers.Count;
                }
            }
            return(result);
        }
Example #28
0
        public void Create(IMap map, Stack <string> RegionNames, Stack <string> baddieNames,
                           FactionName stockBaddieFaction, out int nameIndex, bool addStars = true, bool makeNebulae = false)
        {
            nameIndex = (Utility.Utility.Random).Next(baddieNames.Count);

            this.Map = map;
            this.InitializeSectors(this, new List <Sector>(), baddieNames, stockBaddieFaction, addStars, makeNebulae);

            if (RegionNames != null)
            {
                this.Name = RegionNames.Pop();
            }
        }
Example #29
0
        public static List <Entity> HostilesInPosition(EncounterState state, FactionName parentFaction, int x, int y)
        {
            var hostiles = new List <Entity>();

            foreach (Entity e in state.EntitiesAtPosition(x, y))
            {
                var factionComponent = e.GetComponent <FactionComponent>();
                if (factionComponent != null && factionComponent.Faction != parentFaction)
                {
                    hostiles.Add(e);
                }
            }
            return(hostiles);
        }
Example #30
0
        public void PopulateMatchingItem(Region Region, ICollection <Sector> itemsToPopulate, int x, int y,
                                         Stack <string> baddieNames, FactionName stockBaddieFaction, bool isNebula)
        {
            var sectorItemToPopulate = SectorItem.Empty;

            try
            {
                if (itemsToPopulate != null)
                {
                    if (itemsToPopulate.Count > 0)
                    {
                        Sector sectorToPopulate = itemsToPopulate.SingleOrDefault(i => i.X == x && i.Y == y);

                        if (sectorToPopulate != null)
                        {
                            if ((Region.Type == RegionType.Nebulae) &&
                                (sectorToPopulate.Item == SectorItem.Starbase))
                            {
                                sectorItemToPopulate = SectorItem.Empty;
                            }
                            else
                            {
                                if (!(isNebula && (sectorToPopulate.Item == SectorItem.Starbase)))
                                {
                                    sectorItemToPopulate = sectorToPopulate.Item;
                                }
                            }
                        }
                        else
                        {
                            sectorItemToPopulate = SectorItem.Empty;
                        }

                        //todo: plop item down on map

                        //what does Output read?  cause output is blank
                        //output reads SectorItem.  Is sectorItem.Hostile being added?
                        //todo: new ship(coordinates)?
                        //todo: add to hostiles?
                    }
                }
            }
            catch (Exception ex)
            {
                //throw new GameException(ex.Message);
            }

            this.AddSector(Region, x, y, sectorItemToPopulate, baddieNames, stockBaddieFaction);
        }
Example #31
0
 public static FactionName Opposite(this FactionName faction)
 {
     if (faction == FactionName.PLAYER)
     {
         return(FactionName.ENEMY);
     }
     else if (faction == FactionName.ENEMY)
     {
         return(FactionName.PLAYER);
     }
     else
     {
         throw new NotImplementedException();
     }
 }
Example #32
0
    public void DockingRequest(FactionName dockingFactionName)
    {
        if (Faction.Standings[dockingFactionName] != FactionStanding.Enemy)
        {
            Debug.Log("Docking Request Accepted");

            SaveManager.SaveGame();

            //set the planet to be loaded, then change scenes
            DockedSceneManager.PlanetName = this.PlanetName;
            Application.LoadLevel("DockedScene");
        }
        else
        {
            //TODO add docking request denied message to messages queue (once implemented)
            Debug.Log("Docking Request Denied");
        }
    }
Example #33
0
        public PlayerBox()
        {
            InitializeComponent();

            playerId = nbCreatedPlayers;
            txtName.Text = "Player " + (playerId + 1);

            switch(nbCreatedPlayers)
            {
                case 0: playerColor = Color.FromRgb(200, 64, 64); break;
                case 1: playerColor = Color.FromRgb(64, 64, 200); break;
                case 2: playerColor = Color.FromRgb(64, 200, 64); break;
                case 3: playerColor = Color.FromRgb(200, 180, 64); break;
            }
            rectColor.Fill = new SolidColorBrush(playerColor);
            nbCreatedPlayers++;

            Random rnd = new Random();
            factionChosen = (rnd.Next(3) == 0) ? FactionName.Vikings : ((rnd.Next(2) == 0) ? FactionName.Gauls : FactionName.Dwarves);

            RefreshUI();
        }
Example #34
0
 private void btnDwarf_Click(object sender, RoutedEventArgs e)
 {
     factionChosen = FactionName.Dwarves;
     RefreshUI();
 }
Example #35
0
 private void btnGaul_Click(object sender, RoutedEventArgs e)
 {
     factionChosen = FactionName.Gauls;
     RefreshUI();
 }
Example #36
0
 private void btnViking_Click(object sender, RoutedEventArgs e)
 {
     factionChosen = FactionName.Vikings;
     RefreshUI();
 }
Example #37
0
 private void btnViking_Click(object sender, RoutedEventArgs e)
 {
     this.factionChosen = FactionName.Vikings;
     this.AnyButtonClick();
 }
Example #38
0
 private void btnDwarf_Click(object sender, RoutedEventArgs e)
 {
     this.factionChosen = FactionName.Dwarves;
     this.AnyButtonClick();
 }
Example #39
0
 public PlayerCreator()
 {
     InitializeComponent();
     factionChosen = FactionName.Vikings;
 }