thmsndk / Screeps3D

A 3D client for the MMORTS Screeps.com
89 stars 17 forks source link

Indicate disabled structures #176

Open thmsndk opened 4 years ago

thmsndk commented 4 years ago

When your controller downgrades a structure gets disabled. official-disabled-structures

Extensions have an "off" property in the payload when they are disabled that is true no idea about towers,nukers, labs and factories

https://screeps.com/a/#!/room/shard3/E18S39

https://screeps.com/ptr/api/game/room-objects?shard=shard3&room[$in]=E18S39&room[$in]=E18S39

Now, nuker and factory is "easy" you can only have one and can compare with RCL. but what about towers and labs? what gets disabled?

disabled factory payload

{
    "_id": "5db9d955617154d87830b2fd",
    "type": "factory",
    "x": 31,
    "y": 22,
    "room": "E18S39",
    "notifyWhenAttacked": true,
    "user": "5d9a06a66623cbcc5ede74fb",
    "store": {
        "energy": 5056,
        "Z": 381,
        "zynthium_bar": 0,
        "battery": 0,
        "biomass": 34641
    },
    "storeCapacity": 50000,
    "hits": 1000,
    "hitsMax": 1000,
    "cooldown": 0,
    "actionLog": {
        "produce": null
    },
    "cooldownTime": 14836456
}
thmsndk commented 4 years ago

ags131 deobfuscating the client in #client-dev on slack, theese are all comments from ags :)

slightly deobfuscated snippet:

o = R.roomController ? R.roomController.level : 0;
if (!u.CONTROLLER_STRUCTURES[e.type][0] && (!R.roomController || o < 1 || R.roomController.user != e.user)) {
  return false
}
if (t.length > u.CONTROLLER_STRUCTURES[e.type][o] && (t.sort(W(R.roomController))) {
  t = _.take(t, u.CONTROLLER_STRUCTURES[e.type][o]),
}
return !_.contains(t, e))

looks like it automatically returns false if theres no controller, level < 1, or its not the owner of the room Haven't found the W function yet, but assuming its distance since its passed the controller

W = function (e) {
  return e.pos && (e = e.pos),
    function (t, o) {
      return t.pos && (t = t.pos),
        o.pos && (o = o.pos),
        Math.max(Math.abs(t.x - e.x), Math.abs(t.y - e.y)) - Math.max(Math.abs(o.x - e.x), Math.abs(o.y - e.y))
    }

Yep, returns a distance compare function So looks like it sorts by distance, removes the allowed number of items, then checks if its still in the list, if it is, then it disables