C&C Tiberium Alliances Info - Updated Layout

Relay your levels etc in a wink of an eye.

当前为 2014-07-02 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name           C&C Tiberium Alliances Info - Updated Layout
// @author         Soera and TheStriker(OriginalAuthor) and dbendure
// @description    Relay your levels etc in a wink of an eye.
// @description    Alt+Y - Insert to message/chat/post all your bases/cities info
// @description    Alt+N - Insert to message/chat/post ally support info
// @description    Alt+P - Insert to message/chat/post POI info with infosticker functions ability 
// @namespace      https://prodgame*.alliances.commandandconquer.com/*/index.aspx*
// @include        https://prodgame*.alliances.commandandconquer.com/*/index.aspx*
// @version        1.0.7
// ==/UserScript==
(function () {
  function InfoSticker_IsInstalled() {
				return (typeof (InfoSticker_IsInstalled) != 'undefined' && InfoSticker_IsInstalled);
			}
  var TAI_main = function () {
  
    function createInstance() {
      qx.Class.define("TAI", { //TAS.main
        type : "singleton",
        extend : qx.core.Object,
        members : {
          initialize : function () {
            addEventListener("keyup", this.onKey, false);
            console.log("TA Info loaded.");
			
          },
		
        onKey : function (ev) {
            var s = String.fromCharCode(ev.keyCode);
            var inputField = document.querySelector('input:focus, textarea:focus');
            if (inputField != null) {
              // ALT+
              if (ev.altKey && !ev.altGraphKey && !ev.ctrlKey && !ev.shiftKey && s == "Y") {
                // player bases info to share with others

                var apc = ClientLib.Data.MainData.GetInstance().get_Cities().get_AllCities().d;//all player cities
                var txt = "", c, unitData, bh, supp, type, df;
                for (var key in apc) {
                  c = apc[key];
                  txt += "Def: [b]" + ('0' + c.get_LvlDefense().toFixed(2)).slice(-5) + "[/b] ";
                  txt += "Off: [b]" + ('0' + c.get_LvlOffense().toFixed(2)).slice(-5) + "[/b] ";
                  unitData = c.get_CityBuildingsData();
                  bh = unitData.GetUniqueBuildingByTechName(ClientLib.Base.ETechName.Construction_Yard);
                  df = unitData.GetUniqueBuildingByTechName(ClientLib.Base.ETechName.Defense_Facility);
                  supp = unitData.GetUniqueBuildingByTechName(ClientLib.Base.ETechName.Support_Ion);
                  if (supp === null)
                    supp = unitData.GetUniqueBuildingByTechName(ClientLib.Base.ETechName.Support_Art);
                  if (supp === null)
                    supp = unitData.GetUniqueBuildingByTechName(ClientLib.Base.ETechName.Support_Air);
                  if (bh !== null) {
                    txt += "CY: [b]" + bh.get_CurrentLevel() + "[/b] ";
                    //txt += "[u]BaseRep:[/u] [b]" + (c.get_CityBuildingsData().GetFullRepairTime() / 3600).toFixed(2) + "h[/b] ";
                    //txt += "[u]DefRep:[/u] [b]" + (c.get_CityUnitsData().GetRepairTimeFromEUnitGroup(ClientLib.Data.EUnitGroup.Defense) / 3600).toFixed(2) + "h[/b] ";
                  }
                  if (df !== null) {
                    txt += "DF: [b]" + df.get_CurrentLevel() + "[/b] ";
                  }
                    else {
                        txt += "DF: [b]NA[/b] ";
                    }
                  if (supp !== null) {
                    txt += "" + supp.get_TechGameData_Obj().dn.slice(0, 3) + ": [b]" + supp.get_CurrentLevel() + "[/b] ";
                  }
                    else {
                        txt += "SUP: [b]NA[/b] ";
                    }
                  txt += "--" + "[b][coords]"+ c.get_PosX() + ":" + c.get_PosY() + ":" + c.get_Name() + "[/b][/coords]";
                  txt += "[hr]";
                }
                inputField.value += txt;
              } else if (ev.altKey && !ev.altGraphKey && !ev.ctrlKey && !ev.shiftKey && s == "N") {
                var bases = ClientLib.Data.MainData.GetInstance().get_AllianceSupportState().get_Bases().d;
                var base, keys = Object.keys(bases), len = keys.length, info = {}, avg = 0, high = 0, supBaseCount = len;
                while (len--) {
                  base = bases[keys[len]];
                  if (!info.hasOwnProperty(base.get_Type())) {
                    info[base.get_Type()] = 0;
                  }
                  info[base.get_Type()]++;
                  if (base.get_Level() >= 30)
                    high++;
                  avg += base.get_Level();
                }
                avg /= supBaseCount;
                var members = ClientLib.Data.MainData.GetInstance().get_Alliance().get_MemberData().d, member, baseCount = 0;
                keys = Object.keys(members);
                len = keys.length;
                while (len--) {
                  member = members[keys[len]];
                  baseCount += member.Bases;
                }
                inputField.value += "Bases: " + baseCount + " SupCount: " + supBaseCount + "(" + (supBaseCount / baseCount * 100).toFixed(0) + "%) Avg: " + avg.toFixed(2) + " 30+: " + high + "(" + (high / baseCount * 100).toFixed(0) + "%)";
                //for (var i in info)
                //  console.log("Type: " + i + " Count: " + info[i]);
              }else if (ev.altKey && !ev.altGraphKey && !ev.ctrlKey && !ev.shiftKey && s == "P") {
			   var alliance = ClientLib.Data.MainData.GetInstance().get_Alliance();
			   var pois = alliance.get_POIRankScore();
			   var nextscore = ClientLib.Base.PointOfInterestTypes.GetNextScore;
			   if(this.InfoSticker_IsInstalled == true ){
			   var tib = window.InfoSticker.Base.$$instance.formatNumbersCompact(alliance.get_POITiberiumBonus(), 3);
			   var cry = window.InfoSticker.Base.$$instance.formatNumbersCompact(alliance.get_POICrystalBonus(), 3);
			   var pow = window.InfoSticker.Base.$$instance.formatNumbersCompact(alliance.get_POIPowerBonus(), 3);
			   } else {
			   var tib = alliance.get_POITiberiumBonus();
			   var cry = alliance.get_POICrystalBonus();
			   var pow = alliance.get_POIPowerBonus();
			   }
			   
			   txt += "Tiberium score: [b]" + pois[0].ps +"/"+ nextscore(pois[0].ps) + "[/b] Tiberium rank: [b]" + pois[0].r + "[/b] Tiberium Bonus: [b]" + tib + "[/b]";
			   txt += "[hr]";
			   txt += " Crystal score: [b]" + pois[1].ps +"/"+ nextscore(pois[1].ps) +   "[/b] Crystal rank: [b]" + pois[1].r + "[/b] Crystal Bonus: [b]" + cry + "[/b]";
			   txt += "[hr]";
			   txt += " Power score: [b]" + pois[2].ps +"/"+ nextscore(pois[2].ps) + "[/b] Power rank: [b]" + pois[2].r + "[/b] Power Bonus: [b]" + pow + "[/b]";
			   txt += "[hr]";
			   txt += " Inf score: [b]" + pois[3].ps +"/"+ nextscore(pois[3].ps) + "[/b] Inf rank: [b]" + pois[3].r + "[/b] Inf Bonus: [b]" + alliance.get_POIInfantryBonus() + "%[/b]";
			   txt += "[hr]";
			   txt += " Veh score : [b]" + pois[4].ps +"/"+ nextscore(pois[4].ps) + "[/b] Veh rank : [b]" + pois[4].r + "[/b] Veh Bonus: [b]" + alliance.get_POIVehicleBonus() + "%[/b]";
			   txt += "[hr]";
			   txt += " Air score : [b]" + pois[5].ps +"/"+ nextscore(pois[5].ps) + "[/b] Air rank : [b]" + pois[5].r + "[/b] Air Bonus: [b]" + alliance.get_POIAirBonus() + "%[/b]";
               txt += "[hr]";			   
			   txt += " Def score : [b]" + pois[6].ps +"/"+ nextscore(pois[6].ps) + "[/b] Def rank : [b]" + pois[6].r + "[/b] Def Bonus: [b]" + alliance.get_POIDefenseBonus() + "%[/b]";
			   txt += "[hr]";
			   inputField.value += txt;
			  }
            }
          },
		  
        } // members
      });
    }
	
	

    // Loading
    function TAI_checkIfLoaded() {
      try {
        if (typeof qx != 'undefined') {
          if (qx.core.Init.getApplication().getMenuBar() !== null) {
            createInstance();
            TAI.getInstance().initialize();
          } else setTimeout(TAI_checkIfLoaded, 1000);
        } else {
          setTimeout(TAI_checkIfLoaded, 1000);
        }
      } catch (e) {
        if (typeof console != 'undefined') {
          console.log(e);
        } else if (window.opera) {
          opera.postError(e);
        } else {
          GM_log(e);
        }
      }
    }

    if (/commandandconquer\.com/i.test(document.domain)) {
      setTimeout(TAI_checkIfLoaded, 1000);
    }
  };
  // injecting, because there seem to be problems when creating game interface with unsafeWindow
  var TAIScript = document.createElement("script");
  var txt = TAI_main.toString();
  TAIScript.innerHTML = "(" + txt + ")();";
  TAIScript.type = "text/javascript";
  if (/commandandconquer\.com/i.test(document.domain)) {
    document.getElementsByTagName("head")[0].appendChild(TAIScript);
  }
})();